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 Game Loop and Texture Atlas What is a Texture Atlas?

Jason Meinzer
Jason Meinzer
3,679 Points

Sprites are showing up outside of the screen for iPhone 6 and 6+ - simple fix?

So it's clear this course was designed before the iPhone 6 and 6+ were released, and everything so far looks great on a 5 or 5s, but the sprites are showing up all over the place (some even completely out of the frame) when you run the simulator on a 6 or 6+.

For example, when running the simulator on a 5s, the machine sprite (image) shows up right where it's supposed to, with the shadow on the background_1 image perfectly in place. However, when you run it on a 6 the machine is actually COMPLETELY out of the frame of the screen.

Is there a quick, simple fix to ensure the sprites maintain their position relative to the background_1 and splash_1 screens when running the app on a 6 or 6+?

I searched around online for a while and found mention of ways to perhaps automatically scale the screens up to a 6 or 6+ (with the sacrifice of a little pixelation), but there weren't any clear answers.

2 Answers

Jason Meinzer
Jason Meinzer
3,679 Points

Update: figured it out. Was as simple as adding this single line of code to the initWithSize method:

background.size = self.frame.size;

Full code block for reference:

-(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) {

    self.lastUpdateTimeInterval = 0; //initializing this property
    self.timeSinceEnemyAdded = 0; //initializing this property
    self.addEnemyTimeInterval = 1.25;
    self.totalGameTime = 0;
    self.minSpeed = GameSpaceDogMinSpeed;
    self.restart = NO;
    self.gameOver = NO;
    self.gameOverDisplayed = NO;

    // Setup your scene here....

    SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"background_1"];
    background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
    background.size = self.frame.size;
David Rynn
David Rynn
10,554 Points

For those of use not using the initWithSize method (since it's been deprecated), as Jason Meinzer answered, you can put :

background.size = self.frame.size;

in the -(void)didMoveToView: method in the GamePlayScene.m file. And this should fix the alignment issues. FYI.