cocos2d-x CCAnimate 动画

来源:互联网 发布:vb 连接informix odbc 编辑:程序博客网 时间:2024/05/16 07:30
 CCAnimation* animation = CCAnimation::create();        CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("play.png"); //play.png为一个拥有10帧的图片资源        int eachWidth = this->getContentSize().width/10; //每个帧的宽        for(int i = 0; i < 10; i++)    {        animation->addSpriteFrameWithTexture(texture, CCRectMake(i*eachWidth, 0, eachWidth, this->getContentSize().height));    }        animation->setDelayPerUnit(0.5); //必须设置,否则不会动态播放    animation->setRestoreOriginalFrame(true); //是否回到第一帧    animation->setLoops(-1); //循环次数   -1无限循环        CCFiniteTimeAction* animate = CCAnimate::create(animation);        this->runAction(animate);


this 代表CCSprite