애니메이션도 일종의 액션이라고 보면된다.
1 2 3 4 5 6 7 8 | Animation* ani = Animation::create(); for (int i = 1; i <= 11; i++) { std::string fileName = StringUtils::format("p3_walk%02d.png",i); ani->addSpriteFrameWithFile(fileName); } ani->setLoops(true); ani->setDelayPerUnit(0.08f); | cs |
우선 애니메이션 액션을 만든 후 addSpriteFrameWithFile 함수를 이용하여 이미지를 하나씩 추가해준다.
이후 setDelayPerUnit으로 해당 스프라이트 객체 간의 간격을 설정한다.
위와 같이 설정하면 0.08초마다 다음 스프라이트로 전환이 될 것이다.
애니메이션을 생성했으면 애니메이션을 실행할 Animate를 만들어야 한다.
1 2 3 4 5 | Animate* animate = Animate::create(ani); auto pChar = (Sprite*)getChildByTag(50); pChar->stopAllActions(); RepeatForever* pRepeat = RepeatForever::create(animate); pChar->runAction(pRepeat); | cs |
Animate는 생성한 애니메이션을 넣어 create한 후에 애니메이션효과를 넣을 오브젝트에 runAction하면 된다.
애니메이션을 계속 반복하고싶다면 RepeatForever 액션을 사용하여 Animate를 계속 반복해주면 된다.
'프로그래밍 공부 > cocos2d-x' 카테고리의 다른 글
기타 잡다한 팁들 (0) | 2018.03.28 |
---|---|
사운드 사용하기 (오디오 엔진) (0) | 2018.03.28 |
라벨, 메뉴 사용하기 (0) | 2018.03.28 |
Flappy Bird 게임 만들기 - 2 (0) | 2018.03.27 |
Flappy Bird 게임 만들기 - 1 (0) | 2018.03.27 |