- 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
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