小桑博客

如果渡不过这不可渡的海,将成为这海中捞不起的沙

[Cocos2d-x wiki翻译]Actions

Actions

Actions are like orders given to any CCNode object. These actions usually modify some of the object’s attributes like position, rotation, scale, etc. If these attributes are modified during a period of time, they are CCIntervalAction actions, otherwise they are CCInstantAction actions. For example, the CCMoveBy action modifies the position property during a period of time, hence, it is a subclass of CCIntervalAction.

动作(Actions)就像给CCNode对象的命令一样。这些动作通常会修改对象的一些属性,如位置,旋转,缩放等。如果这些属性在一段时间内被修改,它们是CCIntervalAction动作(延时动作),相反则是 CCInstantAction 动作(瞬间动作).

例如,CCMoveBy动作是在一段时间内修改了位置属性,因此,它是CCIntervalAction的子类.

You can run TestCpp -> Actions Test to see the actions’ visual effects. And cocos2d-x/samples/Cpp/TestCpp/Classes/ActionsTest, ActionsEaseTest are good sample codes for the usage.

你可以运行TestCpp -> Actions Test 来查看动作的可视化效果。cocos2d-x/samples/Cpp/TestCpp/Classes/ActionsTest, ActionsEaseTest中的用法是非常好的代码示例。

例如:

1
2
// Move a sprite 50 pixels to the right, and 10 pixels to the top over 2 seconds.
CCActionInterval*  actionBy = CCMoveBy::create(2, ccp(50,10));
The CCIntervalAction actions have some interesting properties: They can be accelerated using the time-altered actions

CCIntervalAction动作有一些有意思的属性:

使用变速动作可以对CCIntervalAction动作进行加速等,变速动作有:

  • CCEaseIn
  • CCEaseOut
  • CCEaseInOut
  • CCSpeed
Etc. (See the ActionsEaseTest.cpp example for more info)

(更多信息,详见ActionsEaseTest.cpp实例)

You can pause/resume all actions by using the CCActionManager:

你可以通过用CCActionManager来暂停和恢复所有动作:

1
2
3
4
5
6
// Pause actions
CCDirector *director = CCDirector::sharedDirector();
m_pPausedTargets = director->getActionManager()->pauseAllRunningActions();
// resume actions
CCDirector *director = CCDirector::sharedDirector();
director->getActionManager()->resumeTargets(m_pPausedTargets);

Basic Actions

Basic actions are the ones that modify basic properties like:

基本动作是指修改基本属性如:

位置(position)

缩放(scale)

旋转(rotation)

可见性(visible)

不透明度(opacity)

颜色(color)

例如:

1
2
3
4
5
6
CCSprite *sprite = CCSprite::create("Images/grossini.png");
sprite->setPosition(ccp(100, 100));
addChild(sprite);

CCMoveBy* act1 = CCMoveBy::create(0.5, ccp(100, 0));
sprite->runAction(CCRepeat::create(act1, 1));
The act1 will be a CCMoveBy action of duration 0.5, but with the position value of ccp(100,0).

act1是持续0.5秒的CCMoveBy动作,并且使用ccp(100,0)作为移动的位置值.

评论

Comments