SpriteKit junk
SpriteKit junk
- Subject: SpriteKit junk
- From: William Squires <email@hidden>
- Date: Sat, 26 Apr 2014 19:13:12 -0500
Okay, here's a puzzling one... Here's my init method for the SKScene:
-(id)initWithSize:(CGSize)size
{
ERGPlayer *player = [[ERGPlayer alloc] init];
SKAction *tempAction = nil;
SKAction *waitAction = nil;
if (self = [super initWithSize:size])
{
self.currentBackground = [ERGBackground generateNewBackground];
[self addChild:self.currentBackground];
player.position = CGPointMake(100.0, floorHeight + player.size.height);
[self addChild:player];
self.thePlayer = player;
self.score = 0.0f;
self.scoreLabel = [[SKLabelNode alloc] initWithFontNamed:@"Chalkduster"];
self.scoreLabel.fontSize = 15;
self.scoreLabel.color = [UIColor whiteColor];
self.scoreLabel.position = CGPointMake(20.0f, 300.0f);
self.scoreLabel.zPosition = 100;
[self addChild:self.scoreLabel];
self.shieldLabel = [[SKLabelNode alloc] initWithFontNamed:@"Chalkduster"];
self.shieldLabel.fontSize = 15;
self.shieldLabel.color = [UIColor whiteColor];
self.shieldLabel.position = CGPointMake(50.0f, 300.0f);
[self addChild:self.shieldLabel];
tempAction = [SKAction runBlock:^
{
self.scoreLabel.text = [NSString stringWithFormat:@"%3.0f", self.score];
}];
waitAction = [SKAction waitForDuration:0.2];
[self.scoreLabel runAction:[SKAction repeatActionForever:[SKAction sequence:@[tempAction, waitAction]]]];
tempAction = [SKAction runBlock:^
{
self.shieldLabel.text = [NSString stringWithFormat:@"Shields: %.3d%%", self.thePlayer.shieldEnergy];
}];
waitAction = [SKAction waitForDuration:0.1];
[self.shieldLabel runAction:[SKAction repeatActionForever:[SKAction sequence:@[tempAction, waitAction]]]];
self.physicsWorld.gravity = CGVectorMake(0, globalGravity);
}
return self;
}
The score label works, but when rendered, it looks like there's some sort of junk obscuring it (as if the foreground has a mask with randomly set bits here and there), but the shield energy label never renders at all.
The scene consists of:
* an "infinitely" scrolling background (itself an SKSpriteNode whose zPosition is -1 - handled in the update: method)
* a player object (SKSpriteNode referenced as self.thePlayer in other parts of the code - see above)
* a score label (SKLabelNode) to show the score (just a counter of how long the player has run so far.)
* a shield energy label (SKLabelNode) to show shield energy remaining (does nothing... why? >:( )
The following theories don't seem to pan out:
1) The "junk" is part of the scrolling background - this is shot down by the fact that the "junk" doesn't scroll across the rendering of the score label at the same speed as the scrolling background; in fact, the "junk" doesn't move at all (relative to the view/window, but it does change based on the string rendered - see #4 below.)
2) The "junk" is dirt on the screen - this is shot down by the fact that it remains even when I move the iOS simulator window; definitely not dirt on the screen.
3) The "junk" is corruption in the font (in this case, Chalkduster) - this is shot down by the fact that the FPS and node count are shown in the same font, and it's not covered by this "junk" at all!
4) The "junk" is there before anything else is created. If so, why is only the top area of the SKView affected? Also, different characters displayed at the same location show different "junk"; if it was a mask, the "junk" would look the same for all rendered characters in the label at that position on screen. Finally, the "junk" is different depending on the width of the label's underlying .text (i.e. if the text is @"1", it renders nearly perfectly with only a few black dots on it, but if it renders @"15", there's a lot more junk covering up the '1' - weird...)
5) There's something wrong with the code for the "shield energy" label - this is shot down because I just copied and pasted, changing only the location (CGPoint), the reference (self.shieldLabel vs. self.scoreLabel), and the text rendered (in tempAction). Yet the score label renders (albeit strangely), but nothing at all shows up where I would expect the shield energy label to be.
I'd show you what this looks like, but I don't think users are supposed to post pics to this group.
Any ideas on how to iron this out?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden