使用plist文件来创建CCRepeatForever的方法

coco2dx的版本不同带来了很多的问题,尤其是在2.0以后的版本较之前版本又是很大的改动,下面这个是用1.0中的方法在2.0中实现plist动画的一个例子。



CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("bearlist.plist","bearlist.png"); //从名字很容易看出,它是用来缓存图片的,内部封装了一个字典 CCSprite*flowSprite=CCSprite::create(); flowSprite->autorelease(); CCArray*frames=CCArray::create(); for (int i=0;i<<span style="color: #103ffb">6; i++) { char pngName[20]; sprintf(pngName, "bear%d.png",i+1); CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pngName); frames->addObject(frame); } //生成CCAnimation对象 CCAnimation* animation =CCAnimation::createWithSpriteFrames(frames,1./6); //创建动画 // CCAnimation* animation =CCAnimation::create(frames, 1./6, 1); frames->release(); CCAnimate *animate = CCAnimate::create(animation); flowSprite->runAction(CCRepeatForever::create(animate)); this->addChild(flowSprite); flowSprite->setPosition(ccp(200, 200));

  

posted on 2013-12-06 19:31  AS3.0  阅读(227)  评论(0)    收藏  举报

导航