Skip to content

Instantly share code, notes, and snippets.

@ryohey
Created January 24, 2014 03:49
Show Gist options
  • Select an option

  • Save ryohey/8591767 to your computer and use it in GitHub Desktop.

Select an option

Save ryohey/8591767 to your computer and use it in GitHub Desktop.
animate a Sprite from the sprite image in cocos2d-x v3.0beta0
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