cocos2d-x CCAnimation实现动画

CCSprite* sp = CCSprite::create("crop1.png");  

    sp->setPosition(ccp(170, 200));  

    addChild(sp);  

      

    CCAnimation* animation = CCAnimation::create();  

    animation->addSpriteFrameWithFileName("crop1.png");  

    animation->addSpriteFrameWithFileName("crop2.png");  

    animation->addSpriteFrameWithFileName("crop3.png");  

    animation->addSpriteFrameWithFileName("crop4.png");  

      

      

    animation->setDelayPerUnit(1.2); //必须设置否则不会动态播放  

    animation->setRestoreOriginalFrame(true); //是否返回第一帧  

    animation->setLoops(-1); //重复次数   -1无限循环  

      

    CCFiniteTimeAction* animate = CCAnimate::create(animation);  

    sp->runAction(animate);  

 

你可能感兴趣的:(cocos2d-x)