求各位大神解决问题Cocos2dAssertion failed!

qq_22206569 2014-11-11 01:20:42
问题如下:Assert failed: Invalid spriteFrameName: HelloWorld.png
Assertion failed!

Program: ...Rise Of Nois\proj.win32\Debug.win32\libcocos2d.dll
File: f:\cocos2d-x-2.2.5\cocos2dx\sprite_nodes\ccsprite.cpp
Line: 128

Expression: pFrame != 0

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts

就是这一部分的问题
bool BackgroundLayer::init()
{
if ( !CCLayer::init() )
{
return false;
}

CCSize size = CCDirector::sharedDirector()->getWinSize();

CCSprite *item1 = CCSprite::createWithSpriteFrameName("HelloWorld.png");
item1->setPosition(ccp(size.width/2, size.height/2));
addChild(item1);

return true;
}
...全文
510 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
JoeBlackzqq 2014-11-11
  • 打赏
  • 举报
回复
引用 3 楼 qq_22206569 的回复:
[quote=引用 2 楼 musicvs 的回复:] 你没有加载plist的资源吧? 单张的图片应该使用CCSprite::create来创建~
谢谢这位大神,一更改就成功了,非常感谢,想请问一下原因是啥[/quote] 哈哈,自带的cpp-tests中就有例子:Classes\AactionsProgressTest\ActionsProgressTest.cpp中void SpriteProgressWithSpriteFrame::onEnter() 创建方式不同罢了,这是源码:

void SpriteProgressWithSpriteFrame::onEnter()
{
    SpriteDemo::onEnter();

    auto s = Director::getInstance()->getWinSize();

    auto to = Sequence::createWithTwoActions(ProgressTo::create(6, 100), ProgressTo::create(0, 0));

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist");

    auto left = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_01.png"));
    left->setType(ProgressTimer::Type::BAR);
    //    Setup for a bar starting from the bottom since the midpoint is 0 for the y
    left->setMidpoint(Vec2(0.5f, 0.5f));
    //    Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
    left->setBarChangeRate(Vec2(1, 0));
    addChild(left);
    left->setPosition(Vec2(100, s.height/2));
    left->runAction(RepeatForever::create(to->clone()));

    auto middle = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_02.png"));
    middle->setType(ProgressTimer::Type::BAR);
    //    Setup for a bar starting from the bottom since the midpoint is 0 for the y
    middle->setMidpoint(Vec2(0.5f, 0.5f));
    //    Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
    middle->setBarChangeRate(Vec2(1, 1));
    addChild(middle);
    middle->setPosition(Vec2(s.width/2, s.height/2));
    middle->runAction(RepeatForever::create(to->clone()));

    auto right = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_03.png"));
    right->setType(ProgressTimer::Type::RADIAL);
    //    Setup for a bar starting from the bottom since the midpoint is 0 for the y
    right->setMidpoint(Vec2(0.5f, 0.5f));
    //    Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
    right->setBarChangeRate(Vec2(0, 1));
    addChild(right);
    right->setPosition(Vec2(s.width-100, s.height/2));
    right->runAction(RepeatForever::create(to->clone()));
}

笨木头 2014-11-11
  • 打赏
  • 举报
回复
引用 3 楼 qq_22206569 的回复:
[quote=引用 2 楼 musicvs 的回复:] 你没有加载plist的资源吧? 单张的图片应该使用CCSprite::create来创建~
谢谢这位大神,一更改就成功了,非常感谢,想请问一下原因是啥[/quote] 这个,你可能要了解一下TexturePacker打包图片的一些知识~ 粗俗地说,不,是通俗地说,createWithSpriteFrameName是从大图片里取小图片创建精灵,create是直接用一张图片创建精灵。 具体的就要你去搜一下资料详细了解咯~
qq_22206569 2014-11-11
  • 打赏
  • 举报
回复
引用 1 楼 JoeBlackzqq 的回复:
你确定对应的资源文件存在吗? 可以单步调试,看下哪一步错了,看样子是资源不存在呀,看错误信息:Invalid spriteFrameName: HelloWorld.png
恩,先谢谢啦。问题解决了,是该有create创建,图片资源是存在的
qq_22206569 2014-11-11
  • 打赏
  • 举报
回复
引用 2 楼 musicvs 的回复:
你没有加载plist的资源吧? 单张的图片应该使用CCSprite::create来创建~
谢谢这位大神,一更改就成功了,非常感谢,想请问一下原因是啥
笨木头 2014-11-11
  • 打赏
  • 举报
回复
你没有加载plist的资源吧? 单张的图片应该使用CCSprite::create来创建~
JoeBlackzqq 2014-11-11
  • 打赏
  • 举报
回复
你确定对应的资源文件存在吗? 可以单步调试,看下哪一步错了,看样子是资源不存在呀,看错误信息:Invalid spriteFrameName: HelloWorld.png

8,303

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧