Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Game with Sprite Kit Intro to Sprite Kit What is a Node?

Shaun Kelly
Shaun Kelly
5,648 Points

My SKSpriteNode does not show up on my simulator??

#import "GameScene.h"

@implementation GameScene

-(void)didMoveToView:(SKView *)view {
    /* Setup your scene here */

    self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];

    SKSpriteNode *greenNode = [SKSpriteNode spriteNodeWithColor:[SKColor greenColor] size:CGSizeMake(100, 100)];
    greenNode.position = CGPointMake(150, 150);
    [self addChild:greenNode];


}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */

    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];

        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];

        sprite.xScale = 0.5;
        sprite.yScale = 0.5;
        sprite.position = location;

        SKAction *action = [SKAction rotateByAngle:M_PI duration:1];

        [sprite runAction:[SKAction repeatActionForever:action]];

        [self addChild:sprite];
    }
}

-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
}

@end

3 Answers

As per the instructions of the suggested link (by Piotr), I replaced the following line of code:

scene.scaleMode = SKSceneScaleModeAspectFill;

towards the end of the viewDidLoad method with:

scene.scaleMode = SKSceneScaleModeResizeFill;

with the emphasis on the last bit of code (i.e., replacing AspectFill with ResizeFill), and voila, the nodes appear in the simulator!

Adding on to what Shahin said go into GameViewController.m and look in the view did load area make sure you scroll down and look closely for it.Just wanted to add this on because I did not understand at first but then I figured it out.

This worked for me too. Thanks!

Piotr Krzepczak
Piotr Krzepczak
1,906 Points

This is where you can find answer to your issue I think http://stackoverflow.com/questions/25233506/why-wont-my-skspritenodes-not-appear-in-the-scene (it is about Swift but the basic rule is the same for OC).

David Rynn
David Rynn
10,554 Points

I had the same problem but found a simpler solution:

In your GameViewController make sure that you have the line:

```[GameScene sceneWithSize:skView.bounds.size];

To be consistent with the earlier video in this series, instead of the Xcode 6 preloaded 
```[GameScene unarchiveFromFile:@"GameScene"];```

Even though this series is excellent in general, and @[Amit Bijlani](https://teamtreehouse.com/amit) is a great teacher, unfortunately he has not updated this video series to be consistent with Xcode 6 and there have been many changes implemented by Apple since then.