首页 / 软件开发 / .NET编程技术 / cocos2d-基本概念(1)-Basic actions基本动作
cocos2d-基本概念(1)-Basic actions基本动作2011-01-31 博客园 Alexliu译Action就好像给一个cocosNode对象的顺序。这些动作通常用来改变物体的属性,例如位置,旋转,缩放等。如果这些属性在一段时间只能被修改的话,那么这中叫做 IntervalAction 的Action。否则,它们叫做InstantAction 的动作。例如:MoveBy 动作,在一段时间之内,改变了位置这个属性 ,也就是说它是一个IntervalAction的Action。Example:# Move a sprite 50 pixels to the right, and 10 pixels to the top over 2 seconds.
[sprite runAction: [MoveBy actionWithDuration:2 position:ccp(50,10)]];
IntervalAction 有一些很有趣的属性*它们可以通过时间改变来进行加速oEaseInoEaseOutoEaseInOutoSpeedoEtc. (See the EaseActionsTest.m example for more info)*所有相对的动作(以By结尾的)和一些绝对的动作(以 To结尾的)都有一个翻转的动作,执行了一个相反方向的操作。([action reverse])你可以使用pause/resume 来停止和恢复action# Pause actions
[[ActionManager sharedManager ] pauseAllActionsForTarget:sprite ] ;
# resume actions
[[ActionManager sharedManager ] resumeAllActionsForTarget:sprite ] ;
Basic Actions 基本动作以下的每一个动作,除了极为简单的,我都会加入一个简单的事例,以及描述下将会发生的情况。毕竟,都是物体移动,简单上图片,很难表示清楚究竟发生了什么。尤其是那个jump函数。。动作好多。。呵呵。简单应用,对一个box精灵进行移动测试:-(id)init{
self = [super init];
if(nil!=self){
isTouchEnabled = YES;
boxSprite = [Sprite spriteWithFile:@"box.png"];
[boxSprite setPosition:CGPointMake(25, 25)];
[self addChild:boxSprite];
}
return self;
}
- (BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *) event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView: [touch view]];
//动作的定义
//position
//MoveBy
id moveByAction = [MoveBy actionWithDuration:2 position:ccp(30,50)];
//动作的执行
[boxSprite runAction:rotateByAction];
return YES;
}