欢迎转载:http://www.jb51.cc/article/p-zngyomuh-zw.html
本来想写一下帧动画的,搜了一下网上好像有一大把,就懒得写了,直接贴代码。
[cpp] view plain copy print ? //精灵帧缓存 CCSpriteFrameCache*cache=CCSpriteFrameCache::sharedSpriteFrameCache(); //添加pList文件到缓存 cache->addSpriteFramesWithfile("lightning.pList"); //创建数组用来存放帧序列 CCArray*animFrames=CCArray::create(); charstr[64]={0}; for(inti=1;i<=18;++i){ sprintf(str,"lightning%02d.png",i); CCSpriteFrame*frame=cache->spriteFrameByname(str); cclOG(str); //添加帧到数组 animFrames->addobject(frame); } //用帧序列生成帧动画信息,设定帧间隔时间 CCAnimation*animation=CCAnimation::createWithSpriteFrames(animFrames,0.08); animation->setRestoreOriginalFrame(true); //动画缓存,取名字 CCAnimationCache::sharedAnimationCache()->addAnimation(animation,"lightning"); //获取第一帧 CCSpriteFrame*frame=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByname("lightning01.png"); //用第一帧作静态图 CCSprite*first=CCSprite::createWithSpriteFrame(frame); first->setposition(ccp(100,100)); this->addChild(first); //用名字在缓存取帧动画信息 CCAnimation*anim=CCAnimationCache::sharedAnimationCache()->animationByname("lightning"); //有动画信息生成动画 CCAnimate*animate=CCAnimate::create(anim); //执行动画 first->runAction(CCRepeatForever::create(animate));
本来还想做个gif的,mac下的那个软件太贵了,就算了。看个截图
总结
以上是内存溢出为你收集整理的cocos2d-x游戏开发(十六)帧动画全部内容,希望文章能够帮你解决cocos2d-x游戏开发(十六)帧动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)