I am working on my first project in objective-c and I am trying to make an object (that I have coded to move right) run code for the end of the game once it reaches a certain point. I run my app and the object just keeps moving right with no stop. I need to know what I need to do so that game over runs once the object reaches the given point. Any help would be greatly appreciated. I am just getting started with my first project so it is probably something very simple and obvious but I just have not been able to find the answer to my problem anywhere. Again Thanks.Here is my code.
#import "Game.h"
@interface Game ()
@end
@implementation Game
-(IBAction)Play:(id)sender{
PieceMovement = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(PieceMoving) userInfo:nil repeats:YES];
Play.hidden = YES;
}
-(void)GameOver{
Leave.hidden = NO;
[PieceMovement invalidate];
}
-(void) PieceMoving{
Piece.center = CGPointMake(Piece.center.x +5, Piece.center.y);
if (Piece.center.y == 200) {
[self GameOver];
}
}
- (void)viewDidLoad{
Leave.hidden = YES;
}
@end
-------Game.h
#import <UIKit/UIKit.h>
@interface Game : UIViewController
{
IBOutlet UIImageView *Piece;
IBOutlet UIImageView *Chunk;
IBOutlet UIButton *Play;
IBOutlet UIButton *Leave;
NSTimer *PieceMovement;
}
-(IBAction)Play: (id)sender;
-(void)PieceMoving;
-(void)GameOver;
@end
--------Game.h
#import <UIKit/UIKit.h>
@interface Game : UIViewController
{
IBOutlet UIImageView *Piece;
IBOutlet UIImageView *Chunk;
IBOutlet UIButton *Play;
IBOutlet UIButton *Leave;
NSTimer *PieceMovement;
}
-(IBAction)Play: (id)sender;
-(void)PieceMoving;
-(void)GameOver;
@end
Aucun commentaire:
Enregistrer un commentaire