[Action] cocos2d-x 액션 사용법

|


Actions



Actions 클래스는 CCNode 를 상속받는 모든 객체에 명령을 부여합니다. 액션은  오브젝트의 위치, 회전, 크기 기타등등 값들을 수정합니다

일정기간동안 수정하는 작업이면 -> CCIntervalAction actions 그렇지 않으면 -> CCInstantAction 입니다.

 예를들면 CCMoveBy는 일정기간동안 수정합니다. CCIntervalAction 액션입니다.

액션의 사용 예:

1// 스프라이트가 오른족으로  50 픽셀, 밑으로 10 픽셀 움직임 2초동안.
2CCActionInterval*  actionBy = CCMoveBy::create(2, ccp(50,10));


가속 관련된 액션들 (점점 빨라지거나 느려지는등)

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

CCActionManager를 사용하면 중간에 액션을 일시정지 하고 재시작 할수도있다.(해당객체의)

1// Pause actions
2CCDirector *director = CCDirector::sharedDirector();
3m_pPausedTargets = director->getActionManager()->pauseAllRunningActions();
4// resume actions
5CCDirector *director = CCDirector::sharedDirector();
6director->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:

1CCSprite *sprite = CCSprite::create("Images/grossini.png");
2sprite->setPosition(ccp(100, 100));
3addChild(sprite);
4
5CCMoveBy* act1 = CCMoveBy::create(0.5, ccp(100, 0));
6sprite->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).


 뒤에 By 붙는거와 To 붙는거 차이


By는 현재 값 기준으로 변경 To는 그냥 그런거 상관없이 변경

만약 현재 캐릭터 위치가 120 .30 이면

만약 CCMoveBy::create(2, ccp(50,10));    //현재 캐릭터 위치 기준으로 50,10만큼 이동 -> 170,40

       CCMoveTo::create(2ccp(50,10));      //좌표값에 50, 10으로 이동 -> 50,10


Trackback 0 And Comment 0
prev | 1 | 2 | 3 | 4 | 5 | 6 | 7 | next