본문 바로가기

Cocos2d-x v3.17/기본기능

[Cocos2d-x 기본기능]프레임 애니메이션

반응형

프레임 애니메이션 

 

Animate를 사용하여 아주 쉽게 일정시간마다 이미지를 변경해주는 방식이다.아래의 예를 보자 

 

C++ 

auto mySprite = Sprite::create("mysprite.png"); 

// now lets animate the sprite we moved

Vector<SpriteFrame*> animFrames;

animFrames.reserve(12);

animFrames.pushBack(SpriteFrame::create("Blue_Front1.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Front2.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Front3.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Left1.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Left2.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Left3.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Back1.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Back2.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Back3.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Right1.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Right2.png", Rect(0,0,65,81)));

animFrames.pushBack(SpriteFrame::create("Blue_Right3.png", Rect(0,0,65,81))); 

// create the animation out of the frames

Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);

Animate* animate = Animate::create(animation); 

// run it and repeat it forever

mySprite->runAction(RepeatForever::create(animate)); 

 

 

출처:http://cocos2d-x.org/docs/cocos2d-x/zh/actions/basic.html


반응형