In my app I have a uiimageview of a guy. i also have a uiimageview of ball. I want to make it so if the guy runs into the ball he "pushes" it. How can this be done?
my code for moving the guy is as follows:
Code:
-(IBAction)downRight {
[self moveRight];
guyImageView.image = [UIImage imageNamed:@"guy_right.png"]; //right facing image
timerRight = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(moveRight) userInfo:nil repeats:YES];
}
-(IBAction)downLeft {
[self moveLeft];
guyImageView.image = [UIImage imageNamed:@"guy_left.png"]; //left facing image
timerLeft = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(moveLeft) userInfo:nil repeats:YES];
}
-(IBAction)downDown {
guyImageView.image = [UIImage imageNamed:@"guy_down.png"]; //left facing image
[self moveDown];
timerDown = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(moveDown) userInfo:nil repeats:YES];
}
-(IBAction)downUp {
guyImageView.image = [UIImage imageNamed:@"guy_up.png"]; //left facing image
[self moveUp];
timerUp = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(moveUp) userInfo:nil repeats:YES];
}
-(IBAction)upRight {
if (timerRight != nil)
{
[timerRight invalidate];
timerRight = nil;
[self stationaryGuy];
}
}
-(IBAction)upDown {
if (timerDown != nil)
{
[timerDown invalidate];
timerDown = nil;
[self stationaryGuy];
}
}
-(IBAction)upUp {
if (timerUp != nil)
{
[timerUp invalidate];
timerUp = nil;
[self stationaryGuy];
}
}
-(IBAction)upLeft {
if (timerLeft != nil) {
[timerLeft invalidate];
timerLeft = nil;
[self stationaryGuy];
}
}
-(void)moveRight {
guyImageView.frame = CGRectMake(guyImageView.frame.origin.x+HorizontalSquareSize, guyImageView.frame.origin.y, guyImageView.frame.size.width, guyImageView.frame.size.height);
[self checkForBoundry];
}
-(void)moveLeft {
guyImageView.frame = CGRectMake(guyImageView.frame.origin.x-HorizontalSquareSize, guyImageView.frame.origin.y, guyImageView.frame.size.width, guyImageView.frame.size.height);
[self checkForBoundry];
}
-(void)moveUp {
guyImageView.frame = CGRectMake(guyImageView.frame.origin.x, guyImageView.frame.origin.y-VerticalSquareSize, guyImageView.frame.size.width, guyImageView.frame.size.height);
[self checkForBoundry];
}
-(void)moveDown {
guyImageView.frame = CGRectMake(guyImageView.frame.origin.x, guyImageView.frame.origin.y+VerticalSquareSize, guyImageView.frame.size.width, guyImageView.frame.size.height);
[self checkForBoundry];
}
P.S. if your looking for Touch and Hold in buttons, its in my code!
Thanks to anyone who can assist me.