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 Particle Systems and Keeping Score HUD or Heads Up Display

Game Stalling at Title Screen

In building the SpriteKit Game, SpaceCat, just at the "HUD or Heads Up Display" video, I've made it through to almost the end where I've encountered a problem I don't know how to troubleshoot.

when entering the lines of code:

HudNode *hud = [HudNode hudAtPosition:CGPointMake(0, self.frame.size.height-20) inFrame:self.frame]; [self addChild:hud];

... In the GamePlay.m file in the "-(id)initWithSize:(CGSize)size" method, the game gets stuck on the title screen when I run it. Take these two lines out and the game runs as it did before getting to this point in the lesson. What on earth is occurring here to prevent the title screen from switching over to the game play scene?

I've made sure the HudNode files have the correct syntax for calling the +(instancetype) method. I've made sure the scoreLabel position doesn't call for the parent frame.

Are there any error messages being printed in the console?

If not, does the touch on the title screen get picked up? Maybe put a NSLOG in the touch detection code for the tile scene.

Michael, thanks for trying to help.

There were no error messages in the console. The touch did get picked up, indicated by the fact it still played the PressStart sound and the screen went blank. This was a difficult syntax error to discover with no indications of where I made my mistake. I found the problem. Turns out I didn't write the parameters of my 'for' loop in the HudNode Class. It was missing proper syntax for the 'i < hud.lives'.

If anyone knows of an easier way to troubleshoot these kinds of issues other than sifting through all the code, I'd love to hear about it.

Yea I think that would be classified as a logic error and not a syntax error, which would indicate there is no great way to debug unless you step through the code line by line.

Thanks Michael!

I'm still working on using the correct jargon. I appreciate the correction.

2 Answers

This was a difficult logic error to discover with no indications of where I made my mistake. I found the problem. Turns out I didn't write the parameters of my 'for' loop in the HudNode Class. It was missing proper syntax for the 'i < hud.lives'.

Ivan Kazakov
PLUS
Ivan Kazakov
Courses Plus Student 43,317 Points

Hi Misho,

you should give a name to the newly created node as follows:

hud.name = @"HUD";

as it is being referenced by its name with [self childNodeWithName:@"HUD"]; message in at least two methods:

-(void) addPoints:(NSInteger)points -(void)wasteLife.

Sure you can name it whatever you want.

I am not quite sure if it fixes the problem but the line seems to be missing in your initial listing