Cocos2d-x 使用 plist播放动画只显示静态图片

代码如下,网上到处都是这样的代码:



CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache();

cache->addSpriteFramesWithFile(“hero/idle/idle.plist”,“hero/idle/idle.png”);



CCArray *splitAniframe = CCArray::createWithCapacity(4);

CCSpriteFrame *frame;

char *frameNameChar = new char;

for(int i = 0;i< 4;i++)

{

sprintf(frameNameChar, “2001%d.png”,i);

frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameNameChar);

splitAniframe->addObject(frame);

}



CCAnimation *splitAnimation=CCAnimation::createWithSpriteFrames(splitAniframe,0.2f);

splitAnimation->setDelayPerUnit(1.0f);



CCAnimate *splitAnimate=CCAnimate::create(splitAnimation);

CCSprite *testSprite = CCSprite::createWithSpriteFrameName(“20010.png”);

testSprite->setPosition(ccp(500,500));

addChild(testSprite);



testSprite->runAction(CCRepeatForever::create(splitAnimate));



1. 如果我创建精灵的时候直接用 CCSprite::create( ),则什么都不显示。换了createWithSpriteFrameName,则显示第一张图片。

这说明png图片是加载了,也间接的说明 plist文件也是一起可以读取的,但是为毛动画播放不了呢?

谢楼主,用你的方法顺利载入并播放动画了。

不播放应该是没有刷新屏幕吧,你看看是不是sprite载入之后更新图片路径是不是也不能显示变化

楼主 此问题怎么解决啊?

你看下AppDelegate.cpp中方法:void AppDelegate::applicationWillEnterForeground()
CCDirector::sharedDirector()->startAnimation();
上面这行在不在