无法在 cocos2d "No animations were found" 中加载 plist 动画
Can't load plist animation in cocos2d "No animations were found"
我是 cocos2dx 的新手,我在 Windows 上有一个使用 cocos2dx 3.9 的 C++ 项目,我引用了此页面中的 文件动画 示例http://www.cocos2d-x.org/wiki/Sprite_Sheet_Animation;我无法获取 plist 来加载动画。
当我尝试加载 plist 时:
auto cache = AnimationCache::getInstance();
cache->addAnimationsWithFile( "explosion.plist" );
日志显示:
cocos2d: AnimationCache: No animations were found in provided dictionary.
我错过了什么?
此外,我不确定在示例中使用什么来代替 "dance_1"
。它只是第一个动画帧键吗?
The above spritesheet which you are using doesn't have the extension
.png in all the files. You can create a new spritesheet from texture
packer.
To get a sample spritesheet, first goto
`~your-cocos-directory/cocos2d-x-3.9/tests/cpp-tests/Resources/zwoptex/
and copy grossini.plist & grossini.png to your Resources folder.
Sample plist Link
现在从 spritesheet 运行 帧动画,然后首先使用以下命令添加帧:
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("grossini.plist");
现在在动画缓存中添加帧:
Vector<SpriteFrame*> animFrames(15);
char str[100] = {0};
for(int i = 1; i < 15; i++)
{
sprintf(str, "grossini_dance_%02d.png",i);
auto frame = SpriteFrame::create(str,Rect(0,0,40,40)); //we assume that the sprites' dimentions are 40*40 rectangles.
animFrames.pushBack(frame);
}
现在运行动画
auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
auto animate = Animate::create(animation);
sprite->runAction(animate);
希望对您有所帮助。
我是 cocos2dx 的新手,我在 Windows 上有一个使用 cocos2dx 3.9 的 C++ 项目,我引用了此页面中的 文件动画 示例http://www.cocos2d-x.org/wiki/Sprite_Sheet_Animation;我无法获取 plist 来加载动画。
当我尝试加载 plist 时:
auto cache = AnimationCache::getInstance(); cache->addAnimationsWithFile( "explosion.plist" );
日志显示:
cocos2d: AnimationCache: No animations were found in provided dictionary.
我错过了什么?
此外,我不确定在示例中使用什么来代替 "dance_1"
。它只是第一个动画帧键吗?
The above spritesheet which you are using doesn't have the extension .png in all the files. You can create a new spritesheet from texture packer.
To get a sample spritesheet, first goto `~your-cocos-directory/cocos2d-x-3.9/tests/cpp-tests/Resources/zwoptex/ and copy grossini.plist & grossini.png to your Resources folder. Sample plist Link
现在从 spritesheet 运行 帧动画,然后首先使用以下命令添加帧:
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("grossini.plist");
现在在动画缓存中添加帧:
Vector<SpriteFrame*> animFrames(15);
char str[100] = {0};
for(int i = 1; i < 15; i++)
{
sprintf(str, "grossini_dance_%02d.png",i);
auto frame = SpriteFrame::create(str,Rect(0,0,40,40)); //we assume that the sprites' dimentions are 40*40 rectangles.
animFrames.pushBack(frame);
}
现在运行动画
auto animation = Animation::createWithSpriteFrames(animFrames, 0.2f);
auto animate = Animate::create(animation);
sprite->runAction(animate);
希望对您有所帮助。