Cocos2d-x动画CCAnimate CCAnimation

来源:互联网 发布:传奇物品数据库翻译 编辑:程序博客网 时间:2024/05/16 18:19
CCSize size = CCDirector::sharedDirector()->getWinSize();CCSprite *walk = CCSprite::create();walk->setPosition(ccp(size.width/2, size.height/2));this->addChild(walk);//加载图像集CCTexture2D *texture2d = CCTextureCache::sharedTextureCache()->addImage("walk.png");//计算每帧图片的宽高float w = texture2d->getContentSize().width / 4;float h = texture2d->getContentSize().height / 4;//创建动画CCAnimation *animation = CCAnimation::create();animation->setDelayPerUnit(0.3);for (int i = 0; i < 4; i++){     //将第一行的行走姿势逐帧加载到帧框中     animation->addSpriteFrameWithTexture(texture2d, CCRectMake(w * i, 0, w, h));}//基于动画创建动作CCAnimate *animate = CCAnimate::create(animation);//执行动作walk->runAction(CCRepeatForever::create(animate));