0

I have a node with a picture of a box added right on top of another node with image of an airship:

SKSpriteNode *box = [SKSpriteNode spriteNodeWithImageNamed:@"Box"];
box.position = airshipNode.position;
box.physicsBody = [SKPhysicBody bodyWithRectangleOfSize:box.size];
box.physicsBody.categoryBitMask = 1;
box.physicsBody.collisionBitMask = 0;
box.zPosition = airship.zPosition - 1;
[box setScale:0.7];

Now I added a label on top of the box:

SKLabelNode *label = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
CGPoint *position = box.centerRect.origin;
position.y -= 55;
label.position = box.centerRect.origin;
label.text = @"a";
label.fontSize = 70;
label.fontColor = [SKColor blackColor];

Then I added the label onto the box and box onto the main scene:

[box addChild:label];
// self is the main scene.
[self addChild:box];

Then I call these code every 1 second. But the label only appears on some of them and the others are just the box, no label. I also added a fade out action for when the box was tapped. But when the fade out animation is going, the label on the box without the text starts to appear. Any ideas on why the label is not appearing on initializations? Thanks.

Tom Shen
  • 1,838
  • 3
  • 19
  • 40
  • did u see the node count? if the label isn't added then node count isn't increased.MAybe the label is added but you can't see it ? – Teja Nandamuri Dec 13 '15 at 04:29
  • Which line of code are you calling every 1 second? You don't mean you create the same box and label every second, do you? – El Tomato Dec 13 '15 at 05:11
  • @ElTomato All of the codes above will be executed every second – Tom Shen Dec 13 '15 at 06:16
  • why are you stacking sprites on top of each other like this over and over, you are going to run out of memory – Knight0fDragon Dec 13 '15 at 08:37
  • @Knight0fDragon This is the only two I've stacked, the rest are individual. – Tom Shen Dec 13 '15 at 10:05
  • I am a little confused with what you mean by all the code will be executed every 1 second, if you execute all the code every second, then it will constantly stack on you – Knight0fDragon Dec 13 '15 at 15:12
  • I am not constantly stacking them, I am constantly spawning a box onto the main scene and putting an label on top of the box, not stacking one on another every second. – Tom Shen Dec 14 '15 at 14:00

1 Answers1

0

After a bits of researching, I found iOS 9's Sprite Kit handle default z position a bit different than iOS 8. So by adding this line will make all of the labels appear:

label.zPosition = box.zPosition + 1
Tom Shen
  • 1,838
  • 3
  • 19
  • 40