我该如何使用动画在cocos2d? [英] how can I use animation in cocos2d?

查看:141
本文介绍了我该如何使用动画在cocos2d?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个iPhone轮盘游戏。我怎样才能制作动画(旋转)轮盘板?

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

推荐答案

我不知道如何做到这一点在cocos2d(或者,甚至是什么),但你可以使用核心动画无论是与CALayers或UIViews做到这一点。可能是最简单的方法是创建一个包含轮盘的图像一个UIImageView和动画的。

I have no idea how to do this in cocos2d (or even what that is), but you can do this using Core Animation either with CALayers or UIViews. Probably the simplest way would be to create a UIImageView containing an image of your roulette wheel and animate that.

要实现这一点,首先用你轮盘形象进行初始化设置你的UIImageView。当你想将车轮打滑,请使用以下code:

To accomplish this, first set up your UIImageView by initializing it with your roulette wheel image. When you want the wheel to spin, use the following code:

CATransform3D rotationTransform = CATransform3DMakeRotation(1.0f * M_PI, 0, 0, 1.0);

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];

rotationAnimation.toValue = [NSValue valueWithCATransform3D:rotationTransform];
rotationAnimation.duration = 0.25f;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 10; 

[rotatingImage.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

假设rotatingImage是你的UIImageView。

assuming that rotatingImage is your UIImageView.

在这个例子中,轮将旋转5次,每次旋转服用0.5秒。该旋转被分成两半,因为核心动画将前往最接近的状态,因此您可以旋转的东西最多的是半旋转动画要在另一个方向转动了。也就是说,这里的PI弧度(180度)旋转进了半圈,但如果你使用(1.5F * PI)为您的旋转角度,它只会去四分之一圆。同样,如果你使用(0.999f * PI),圆会以顺时针的方式旋转。

In this example, the wheel would rotate 5 times, with each rotation taking 0.5 seconds. The rotations are split in half because Core Animation will go to the next closest state, so the most you can rotate something is a half rotation before the animation wants to rotate in the other direction. That is, the pi radian (180 degree) rotation here goes a half-circle, but if you used (1.5f * pi) for your rotation angle, it would only go a quarter-circle. Likewise, if you used (0.999f * pi), the circle would rotate in a clockwise manner.

您会想实现你的车轮加速和减速,而对于那些一CAKeyframeAnimation将采取CABasicAnimation的地方在这个例子中。

You'll want to implement acceleration and deceleration of your wheel, and for those a CAKeyframeAnimation would take the place of the CABasicAnimation in this example.

这篇关于我该如何使用动画在cocos2d?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆