Created
January 24, 2014 03:49
-
-
Save ryohey/8591767 to your computer and use it in GitHub Desktop.
animate a Sprite from the sprite image in cocos2d-x v3.0beta0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Size size = Size(128, 128); | |
| auto frames = new Vector<SpriteFrame *>(); | |
| for (int x = 0; x <= 10; ++x) { | |
| auto rect = Rect(x * size.width, 0, size.width, size.height); | |
| auto frame = SpriteFrame::create("walkingZombieSprite.png", rect); | |
| frames->pushBack(frame); | |
| } | |
| auto animation = Animation::createWithSpriteFrames(*frames); | |
| animation->setLoops(-1); // loop forever | |
| animation->setDelayPerUnit(0.1); | |
| auto animate = Animate::create(animation); | |
| auto zombie = Sprite::create(); | |
| zombie->runAction(animate); | |
| zombie->setContentSize(size); // set correct size, 0 x 0 by default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment