Pregunta

I'm using UIKit to create a simple game. In my game, I want the ball to completely stop moving if its upMovement is less than -4.

So it appears to freeze in mid air.

What I have is the following:

    if (upMovement < -4) {

    upMovement = 0;
    ball.center = CGPointMake(ball.center.x, ball.center.y);

    ball.animationImages = [NSArray arrayWithObjects:
                           [UIImage imageNamed:@"fallingball.png"], nil];
    [ball setAnimationRepeatCount:0];
    ball.animationDuration = 1;
    [ball startAnimating];
}

I thought by adding upMovement = 0; and ball.center = CGPointMake(ball.center.x, ball.center.y) it would freeze the ball as soon as the upMovement < -4 ? but instead it, just makes it move really slow.

Any reasons as to why?

¿Fue útil?

Solución

If your ball view is animating because of an UIView animation block or similar, then

[ball.layer removeAllAnimations];

should remove that animation and freeze it in place.

If you're animating it in place by repeatedly changing its frame then you would just have to stop doing that.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top