首页 > 代码库 > (七) 动画

(七) 动画

自定义序列帧动画:

Animation* animation = Animation::create();SpriteFrameCache* spriteFrameCache = SpriteFrameCache::getInstance();spriteFrameCache->addSpriteFramesWithFile("Peashooter.plist");char str[64] = { 0 };for (int i = 1; i <= 13; i++){    sprintf(str, "Peashooter%d.png", i);    animation->addSpriteFrame(spriteFrameCache->getSpriteFrameByName(str));}animation->setDelayPerUnit(1.0f / 12.0f);animation->setLoops(-1);Animate* animate = Animate::create(animation);Sprite* sprite = Sprite::createWithSpriteFrameName("Peashooter1.png");sprite->setPosition(ccp(100, 100));this->addChild(sprite);sprite->runAction(animate);