void Player::run() { SpriteFrameCache* spriteFrameCache = SpriteFrameCache::getInstance(); spriteFrameCache->addSpriteFramesWithFile("boys.plist", "boys.png"); Vector<SpriteFrame*> spriteFrameArray; SpriteFrame* spriteFrame = nullptr; for (int i = 0; i < 15; i++) { spriteFrame = spriteFrameCache->getSpriteFrameByName(StringUtils::format("run%i.png", i + 1)); spriteFrameArray.pushBack(spriteFrame); } auto animation = Animation::createWithSpriteFrames(spriteFrameArray, 0.08, -1); Animate* animate = Animate::create(animation); getSprite()->runAction(animate); }
這裏用到了一張打包的圖片,共15個動做,組成一個跑動的效果,實際運用中以實際需求調整。orm