Xcode project I can't figure out

Joined
Jul 25, 2014
Messages
1
Reaction score
0
Points
1
I hope i'm posting this in the right spot, but I'm new to iOS development and Objective-C in general. I've coded the basics of my first app, a style of Flappy Bird, in Xcode 5.1 and up until this point I haven't reached any problems.

What I am trying to make happen is when the "Bird" intercects the "Pipe", I want the "Bird" to fall to the bottom of the screen, then stop at the bottom. After this, I would make the Bird head disapear ( Bird.hidden = YES; ) and display two different image views, each image being half of the Bird that hit the ground. After the two images are displayed at the bottom of the screen, I want them to fly in different direction (giving each image "arc4random()"?) and a cartoon image of an explotion will appear.

At first this sounded simple in logic to me, but I ran into a problem:

if (CGRectIntersectsRect(Bird.frame, TunnelTop.frame)) {
[self GameOver];

}

if (CGRectIntersectsRect(Bird.frame, TunnelBottom.frame)) {
[self GameOver];

}

if (CGRectIntersectsRect(Bird.frame, Top.frame)) {
[self GameOver];

}


if (CGRectIntersectsRect(Bird.frame, Bottom.frame)) {
[self GameOver];


}


This is the code that runs the method -(void)GameOver. So when the "Bird" intercects the "Tube", it then runs -(void)GameOver.

-(void)GameOver{

if (ScoreNumber > HighScoreNumber) {
[[NSUserDefaults standardUserDefaults] setInteger:ScoreNumber forKey: @"HighScoreSaved"];
}

[TunnelMovement invalidate];
[BirdMovement invalidate];

Exit.hidden = NO;


}


This is the method -(void)GameOver. The [BirdMovement invalidate]; is where I come across the problem. If I run that anywhere in the code off game over (even in its own submethod) the Bird just stops right where it hits the tunnel. If I don't include [BirdMovement invalidate]; then the bird falls how I want it too...but with some other problems.

1. The Bird doesn't stop at the bottom, it continues off the screen.
2. The user can still control the flight of the bird "Up" and "Down", but the tunnels don't move because i invalidated the tunnels.
3. If the user clicks the Exit Game button i've added and then plays the game again WITHOUT exiting and reopening the app, the Bird becomes a lot harder to control. The issue being something with the NSTimer that makes the head fall every 0.05 seconds; the unit at which the head is falling at increases for some reason.

I figured I might need to create a whole new .h and .m file for this, but all my variables and methods got mixed up and I had to delete a whole weeks worth of work trying to get this to work.

I can probably figure out the rest of the code as long as I get this bird falling problem solved...thanks for the help.... oh and btw, no one in the Apple Developer Forms could help me :Grimmace:
 
Joined
Feb 25, 2009
Messages
2,112
Reaction score
71
Points
48
Your Mac's Specs
Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
Although I don't code games often, looking at what you've posted, it'd be impossible to help.

This code is a small subset of your entire project. I *assume* your invalidates there are timers specific to the movement? it's no wonder it won't move after invalidation - the timer no longer fires so no more animation will be performed. If you take the invalidates out, it would make sense that the animations would continue.

You need to consider what you are attempting to do, and in that:

* finish animating death of bird object
* During death animation (falling of the bird, splitting of bird) reject any input that would adjust the trajectory of the bird.
* Change your animation code for the death sequence to detect when it collides with the bottom to split the bird (in reference to it falling through the bottom)
* Check all of your timer code, timers don't usually magically change their intervals - somewhere something is getting tweaked to change the timer interval (or code in interpreting the interval if it's time to actually perform and action) - something is getting changed.

From what you've posted in code, I'd personally have to say it's operating as expected. If the bird hits the tunnel, send a message to endgame method, check if new score is a high score, if it is save it, stop the timers for the animations, display the exit button...

There is more to your code that is involved in this death effect and you need to inspect the whole amount of code, what you've posted is, unfortunately, most likely not the problem or at least not the complete problem. You need to handle your death logic which appears to not be in this method. Maybe setup another timer to animate the death of the bird? Set a flag so if that flag is true directional input will be ignored?
 
Joined
Oct 11, 2014
Messages
1
Reaction score
0
Points
1
Location
San Jose, CA
Your Mac's Specs
Mid 2010 MacBook 4GB
I need to start this reply with more qualifiers than answer, but..... I'm new to this forum and certainly not the sharp knife in the drawer when it comes to iOS coding... And I've never written a game before. I'm more of a database app kinda guy.

That having been said, it seems to me that part of your issue, if you haven't yet solved it, revolves around code blocks and thread safing. If the animation is not completing or ending or moving unexpectedly, it could be due to things not getting the chance to complete in the single thread your app runs in.

I certainly couldn't presume to find anything in your code, but the issue of execution order and sequencing suggests you'd need more direct control over the objects. Just my two cents....
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top