一,CCActionManager管理所有节点动作的对象
来看看打飞机里面的一个onEnter方法
-
(void)onEnter{ [super
onEnter]; //一定要注意添加此方法,否则将停留在开始界面 CGSize
winSize = [[CCDirector sharedDirector] winSize]; [CCMenuItemFont
setFontSize:20]; [CCMenuItemFont
setFontName:@"Arial"]; CCMenuItemFont
*startItem = [CCMenuItemFont itemWithString:@"开始游戏"
block:^(id sender) { _isGameStarted
= YES; CCMenuItem
*item = (CCMenuItemFont*)sender; item.visible
= NO; //6.spawn
enemy after 1.0 sec [self
performSelector:@selector(spawnEnemy) withObject:nil afterDelay:1.0f]; //7.enable
accelerometer self.isAccelerometerEnabled
= YES; //9.enable
touch self.isTouchEnabled
= YES; }]; startItem.position
= ccp(winSize.width / 2,
-winSize.height / 2); _startGameMenu
= [CCMenu menuWithItems:startItem, nil]; _startGameMenu.position
= CGPointZero; [self
addChild:_startGameMenu]; //7
基本动作 从原来的位置移动到新的位置 id
moveBy = [CCMoveBy actionWithDuration:1.0
position:ccp(0,
winSize.height)]; //位置的移动 [_startGameMenu
runAction:moveBy]; //开始移动 //8
和位置有关的基本动作 //1
CCActionManager [[[CCDirector
sharedDirector] actionManager ] pauseTarget:_startGameMenu];//暂停 [self
schedule:@selector(resumeStartMenuAction:)
interval:1.0];
//等待十秒之后才能开始移动 //2CCAction
抽象类,几乎所有的类都继承该类 //3.CCFiniteTimeAction
该类为有限时间动作,包含CCActionInstant 瞬时动作 和CCActionInterval 区间动作,他们包含了很多不同的动作 //4
CCRepaeatForever 无限重复的动作 //5跟随节点的动作CCFollow
.可以替代Camera //6
CCSpeed 更还节点动作的速度。 //
7CCOrbitCamera 继承与CCActionCamera 。使用球坐标系围绕屏幕中心旋转摄像机的视角 }-
(void)resumeStartMenuAction:(ccTime)dt{ [self
unschedule:_cmd]; //停止当前动作 [[[CCDirector
sharedDirector]actionManager] resumeTarget:_startGameMenu];}
二,基本动作:和位置相关的基本动作
CGSize
winSize = [[CCDirector sharedDirector] winSize]; CCSprite
*plane = [CCSprite spriteWithFile:@"hero_1.png"]; plane.position
= ccp(winSize.width/2,
winSize.height/2); [self
addChild:plane]; //2
moveBy 让节点对象在一定时间内移动一定的像素值 ,这个是相对于原位置的 [plane
runAction:[CCMoveBy actionWithDuration:3
position:ccp(50,
0)]]; //3
CCjumpTo [plane
runAction:[CCJumpTo actionWithDuration:4
position:ccp(winSize.width, winSize.height) height:40
jumps:3]]; //4CCJumpBy
相对于原位置的移动 ,相对于原位置的偏移量为 100,0 [plane
runAction:[CCJumpBy actionWithDuration:3
position:ccp(100,
0)
height:100
jumps:4]]; //5CCBezier
TO ccBezierConfig
c = {ccp(300,
100),ccp(50,
50),ccp(-50,
-50)}; //1.参数一
相对于原位置的偏移,2,3分别是贝塞尔曲线的两个控制点 [plane
runAction:[CCBezierTo actionWithDuration:3
bezier:c]]; //6
CCplace 将对象直接放到指定的位置 [plane
runAction:[CCPlace actionWithPosition:ccp(10,
10)]];
三,和大小相关的基本动作
//二 和大小相关的基本动作
// 1 CCScale TO、放大为原来的两倍
[plane runAction:[CCScaleTo actionWithDuration:2 scale:2]];
//2 CCScale By 缩小相应的倍数
[plane runAction:[CCScaleBy actionWithDuration:3 scale:3]];
[plane runAction:[CCScaleBy actionWithDuration:3 scaleX:0.5 scaleY:0.5]]; //对象的高度和宽度的缩小
本文详细介绍了在游戏开发中如何使用Cocos2d-x引擎实现节点的动作变化和大小调整,包括位置移动、大小缩放等基本操作,并通过实例展示了具体应用。
1229

被折叠的 条评论
为什么被折叠?



