Actions are orders given to a 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.
You can run TestCpp->Actions
test to see the action's visual effects. And cocos2d-x/samples/Cpp/TestCpp/Classes/ActionsTest
, ActionsEaseTest are good sample codes for the usage.
Example:
// Move a sprite 50 pixels to the right, and 10 pixels to the top over 2 seconds.2CCActionInterval* actionBy = CCMoveBy::create(2, ccp(50,10));
The CCIntervalAction actions have some interesting properties: They can be accelerated using the time-altered actions
- CCEaseIn
- CCEaseOut
- CCEaseInOut
- CCSpeed Etc. (See the ActionsEaseTest.cpp example for more info)
You can pause/resume all actions by using the CCActionManager:
// Pause actionsCCDirector *director = CCDirector::sharedDirector();m_pPausedTargets = director->getActionManager()->pauseAllRunningActions();// resume actionsCCDirector *director = CCDirector::sharedDirector();director->getActionManager()->resumeTargets(m_pPausedTargets);
###Basic Actions Basic actions are the ones that modify basic properties like:
####Position
- CCMoveBy
- CCMoveTo
- CCJumpBy
- CCJumpTo
- CCBezierBy
- CCBezierTo
- CCPlace
####Scale
- CCScaleBy
- CCScaleTo
####Rotation
- CCRotateBy
- CCRotateTo
####Visibility
-
CCShow
-
CCHide
-
CCBlink
-
CCToggleVisibility
-
Opacity
-
CCFadeIn
-
CCFadeOut
-
CCFadeTo
####Color
- CCTintBy
- CCTintTo
Example:
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));