how can I use animation in cocos2d?

后端 未结 4 580
广开言路
广开言路 2020-12-02 12:41

I am trying to develop a Roulette game for iPhone. How can I animation (spin) the Roulette board?

4条回答
  •  没有蜡笔的小新
    2020-12-02 13:05

    You can rotate a view, by some number of radians, regardless of whether it is less than a full rotation or many multiples of a full rotation, without having to split the rotation into pieces. As an example, the following code will spin a view, once per second, for a specified number of seconds. You can easily modify it to spin a view by a certain number of rotations, or by some number of radians.

    - (void) runSpinAnimationWithDuration:(CGFloat) duration;
    {
        CABasicAnimation* rotationAnimation;
        rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
        rotationAnimation.duration = duration;
        rotationAnimation.cumulative = YES;
        rotationAnimation.repeatCount = 1.0; 
        rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    
        [myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    }
    

提交回复
热议问题