How to add coordinate restrictions to an image
I have 2 buttons that i hold down and they move an image across the
screen, left or right, i want he image to stop at the edge of the screen
though and not be able to move any further, i am at a loss for how to add
the code to do that though.
-(IBAction)Left:(id)sender{
[MenuClick play];
LeftTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self
selector:@selector(GoLeft) userInfo:nil repeats:YES];
if (Left == nil) {
LeftTimer = [NSTimer scheduledTimerWithTimeInterval:0.05
target:self selector:@selector(GoLeft) userInfo:nil repeats:YES];
}
}
-(IBAction)StopLeft:(id)sender{
[LeftTimer invalidate];
LeftTimer = nil;
}
-(IBAction)Right:(id)sender{
[MenuClick play];
RightTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self
selector:@selector(GoRight) userInfo:nil repeats:YES];
if (Right == nil) {
RightTimer = [NSTimer scheduledTimerWithTimeInterval:0.05
target:self selector:@selector(GoRight) userInfo:nil repeats:YES];
}
}
-(IBAction)StopRight:(id)sender{
[RightTimer invalidate];
RightTimer = nil;
}
-(void)GoLeft{
Ship.center = CGPointMake(Ship.center.x -5, Ship.center.y);
}
-(void)GoRight{
Ship.center = CGPointMake(Ship.center.x +5, Ship.center.y);
}
No comments:
Post a Comment