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

SpaceCat Scores

Post your Scores!

Anyone experiencing freezing after about 39000?

Anyway My top score is 43300 posted the pick via twitter account.

4 Answers

Mine was freezing a lot quicker at around 10,000 for some reason, it's an iPhone 5 but it runs 3D games so well

I have the 5s. I'm going through the course now. As soon as I complete it. I plan on debugging it.

Aaron Ackerman Did you ever find out what the bug is? I finished the course, I have no idea what's causing the frame rate drops. I dropped the settings a ton for the particles/explosions. I have a feeling that Amit Bijlani is trying to teach us something and did this on purpose haha

Aaron Ackerman Think I may have found the solution! In the "createDebrisAtPosition" method in the GamePlayScene implementation, I dropped the randomWithMin to 3 and the max to 10, and the game is a lot smoother. I think there were some collisions that randomly produces 20 nodes of debris and if those go off at the same time it causes lag.

Hi Eliot, I was going to post this along with some of the other changes I made to the game. createDebrisAtPosition is the reason behind the game freezing up. Looks like you found the answer too. : ) I also have been playing with a fade out effect it looks really cool but does not help with the issue lol.

-(void) createDebrisAtPoition:(CGPoint)position {

    NSInteger numberOfPiceces = [MavUtil randomWithMin:5 max:20];


    for (int i=0; i < numberOfPiceces; i++) {
        NSInteger randomPiece = [MavUtil randomWithMin:1 max:4];
        NSString *imageName = [NSString stringWithFormat:@"debri_%ld",randomPiece];

        SKSpriteNode *debris = [SKSpriteNode spriteNodeWithImageNamed:imageName];
        debris.position = position;
        [self addChild:debris];

        debris.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:debris.frame.size];
        debris.physicsBody.categoryBitMask = MavCollisionCategoryDebris;
        debris.physicsBody.collisionBitMask = MavCollisionCategoryGround | MavCollisionCategoryDebris;
        debris.name = @"Debris";

        debris.physicsBody.velocity = CGVectorMake([MavUtil randomWithMin:-150 max:150], [MavUtil randomWithMin:150 max:350]);

//add this line below! 
        [debris runAction:[SKAction fadeOutWithDuration:2.7] completion:^{

            [debris removeFromParent];
        }];

    }

Tip: Try adding Sleep before the restart text appears. This gives the user a chance to see his or her score before trying again.

-(void) performAnimation {
    SKLabelNode *label = (SKLabelNode*)[self childNodeWithName:@"GameOver"];
    label.xScale = 0;
    label.yScale = 0;
    SKAction *scaleup = [SKAction scaleTo:1.2f duration:0.75f];
    SKAction *scaleDown = [SKAction scaleTo:0.9f duration:0.25f];

    SKAction *run = [SKAction runBlock:^{
        SKLabelNode *touchToRestart = [SKLabelNode labelNodeWithFontNamed:@"Futura-CondensedExtraBold"];
        touchToRestart.text = @"Touch to try Again!";
        touchToRestart.fontSize = 24;
        touchToRestart.fontColor = [SKColor redColor];
        touchToRestart.position = CGPointMake(label.position.x, label.position.y-40);

         sleep(1.0); // Add this line here 
        [self addChild:touchToRestart];


    }];

Change the text color based on score:

-(void) addPoints:(NSInteger)points {
    self.score += points;

    SKLabelNode *scoreLabel = (SKLabelNode*)[self childNodeWithName:@"Score"];
    scoreLabel.text = [NSString stringWithFormat:@"%ld",(long)self.score];

//Add the if statement and adjust the score 
    if (self.score < 100) {
        scoreLabel.fontColor = [SKColor redColor];
    }

}

How to move the background!

It's not as awesome as I thought it would be but it does add some extra animation to the game.

//GamePlayScence.m

SKSpriteNode *background =[SKSpriteNode spriteNodeWithImageNamed:@"background_1"];
        background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
        SKAction *moveBackGroundRight = [SKAction moveByX:7 y:1 duration:2.5];
        SKAction *moveBackGroundLeft = [SKAction moveByX:-7 y:-1 duration:1.5];
        SKAction *moveDown =[SKAction moveByX:0 y:8 duration:1];
        SKAction *moveUp = [SKAction moveByX:0 y:-8 duration:0.7];
        SKAction *moveAround = [SKAction group:@[moveBackGroundRight,moveBackGroundLeft,moveUp,moveDown]];
        SKAction *moveForever = [SKAction repeatActionForever:moveAround];

        [background runAction:moveForever];

        [self addChild:background];