cocos2d-x帧动画

前端之家收集整理的这篇文章主要介绍了cocos2d-x帧动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
auto cache = SpriteFrameCache::getInstance();
    cache->addSpriteFramesWithFile("MainMap/HorseCar/001/NewAnimation0.plist");
    Sprite* horse = Sprite::createWithSpriteFrameName("fonts/001/10000.png");//plist里面的key
    imgMap->addChild(horse);
    horse->setPosition(Vec2(1350,900));

    Vector<SpriteFrame*> frames(11);//把所有马车加入Vector
    auto frame1 = cache->getSpriteFrameByName("fonts/001/10000.png");
    auto frame2 = cache->getSpriteFrameByName("fonts/001/10002.png");
    auto frame3 = cache->getSpriteFrameByName("fonts/001/10004.png");
    auto frame4 = cache->getSpriteFrameByName("fonts/001/10006.png");
    auto frame5 = cache->getSpriteFrameByName("fonts/001/10008.png");
    auto frame6 = cache->getSpriteFrameByName("fonts/001/10010.png");
    auto frame7 = cache->getSpriteFrameByName("fonts/001/10012.png");
    auto frame8 = cache->getSpriteFrameByName("fonts/001/10014.png");
    auto frame9 = cache->getSpriteFrameByName("fonts/001/10016.png");
    auto frame10 = cache->getSpriteFrameByName("fonts/001/10018.png");
    auto frame11 = cache->getSpriteFrameByName("fonts/001/10020.png");

    frames.pushBack(frame1);
    frames.pushBack(frame2);
    frames.pushBack(frame3);
    frames.pushBack(frame4);
    frames.pushBack(frame5);
    frames.pushBack(frame6);
    frames.pushBack(frame7);
    frames.pushBack(frame8);
    frames.pushBack(frame9);
    frames.pushBack(frame10);
    frames.pushBack(frame11);

    auto animation = Animation::createWithSpriteFrames(frames,0.1);//间隔时间
    horse->runAction(RepeatForever::create(Animate::create(animation)));
    horse->runAction(MoveTo::create(10,Vec2(1000,900)));
原文链接:https://www.f2er.com/cocos2dx/340511.html

猜你在找的Cocos2d-x相关文章