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

Help! iOS

I am writing an app but am stuck.

if (Ball.center.y < 307) { [self PlacePlatform]; }

PlacePlatform makes the platform in the game regenerate in a random place across the x axis. But as the ball falls and gets past 307 on the y axis, the platform keeps on regenerating over and over again as the code tells it. I only want this to happen once? Help will be very much appreciated as i am only new to iOS.

3 Answers

If i send you the code please could you look at it for me and tell me where I am going wrong?:(

Sure. Shoot me a dropbox link or something.

Without seeing the rest of your code, this is likely happening because the ball continues to be beneath the y threshold for every run of the game loop.

A quickie solution would be to set a class variable to track if the platform has been created. Up in the class implementation add something like BOOL _platformLoaded = NO

Then

if (Ball.center.y < 307) { 
   [self PlacePlatform]; 
   _platformLoaded = YES;
}

Then elsewhere you test if the y point is greater than or equal to 307 and reset the _platformLoaded = NO. Perhaps in the else clause?

Again, this is just shooting from the hip without looking at your code.

If i send you the code please could you look at it for me and tell me where I am going wrong?

Sorry i don't have a dropbox account, would i be able to email it you? my email is lewisstones96@gmail.com if you want to email me your email address. Thanks for the help!