iphone - how can I use animation in cocos2d? -


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

I do not know how to do this in Cocos 2D (or even whatever ), But you can do this by using Core Aeries or with CALayers or UIViews. Perhaps the simplest way would be to create and animate UIMJEWviewview with an image of your roulette wheel.

To complete this, first start up your UIImageView with your Roulette Wheel image and set it up. When you want to spin the wheel, use the following code:

  CATransform3D rotationTransform = CATransform3DMakeRotation (1.0f * M_PI, 0, 0, 1.0); CABasicAnimation * RotationAnimation; Rotation animation = [with CABasic animation animation: @ "Transformation"]; Rotation animation.tv = [NSW Value ValueCatransform 3D: Rotation Transform]; Rotation animation Duration = 0.25 f; Rotation animation resolution = yes; Rotation animation.repeatcode = 10; [RotatingImage.layer addAnimation: Rotation for animation: @ "rotation animation"];  

Assuming that rotatingImage is your UIImageView.

In this example, the wheel will rotate 5 times, taking 0.5 seconds with each rotation. Rotation is divided into half because the core animation will move to the next nearest state, so the more you can do half rotation before the animation moves in the other direction. That is, PI radian (180 degrees) rotation here is half a circle, but if you use (1.5 F * P) for your rotation angle, then it will be only one fourth cycle. Similarly, if you used (0.999f * pi), the circle would rotate clockwise.

You want to apply the acceleration and slowdown of your wheel, and for those who will replace kickback frames, CABasicAnimation in this example.


Comments