Monday, December 31, 2012

[iOS] Jumping into iphone game development

If your character image is too big to catch a collision, you may need to make hidden rectangle for the jump action. When the jump action is called, it will move both of the actual image and collisionRect frame. Collision method only check the collision between hws and collisionRect.




- (void) fall
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.8];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animateRunning)];
    characterImage.frame = CGRectMake(characterImage.frame.origin.x, 90 +30, 175, 181);
    collisionRect.frame = CGRectMake(collisionRect.frame.origin.x, 90 +90, 26, 111);
    [UIView commitAnimations];
}

- (IBAction) jump
{
    [characterImage setAnimationImages:jumpAni];
    [characterImage setAnimationDuration:1];
    [characterImage setAnimationRepeatCount:1];
    [characterImage startAnimating];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(fall)];
    collisionRect.frame = CGRectMake(collisionRect.frame.origin.x, 90 -90, 26, 111);
    
    characterImage.frame = CGRectMake(characterImage.frame.origin.x, 90 -30, 175, 181);
    [UIView commitAnimations];
    [characterImage startAnimating];

}

No comments: