cocosstudio2.0.5发布的csb资源,程序加载成功但是不显示图片

// on “init” you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}

auto node = CSLoader::createNode("res/MainScene.csb");
addChild(node, 10);

return true;

}

如上代码,在cocosstudio2.0.5的工具里面制作了一个场景文件,代码加载后,只显示文件,不显示任何图片。目前用的cocos2dx.3.3-RC2的版本,cocosstudio用的是2.0.5的版本。求大大们帮助一下.

输出里边有什么错误没

classname = Button
cocos2d: fullPathForFilename: No file found at bt_com.png. Possible missing file.
cocos2d: fullPathForFilename: No file found at bt_com.png. Possible missing file.
cocos2d: fullPathForFilename: No file found at bt_com.png. Possible missing file.
Get data from file(bt_com.png) failed, error code is 2
cocos2d: fullPathForFilename: No file found at bt_buy_small.png. Possible missing file.
cocos2d: fullPathForFilename: No file found at bt_buy_small.png. Possible missing file.
cocos2d: fullPathForFilename: No file found at bt_buy_small.png. Possible missing file.
Get data from file(bt_buy_small.png) failed, error code is 2
cocos2d: fullPathForFilename: No file found at bt_com.png. Possible missing file.
cocos2d: fullPathForFilename: No file found at bt_com.png. Possible missing file.
cocos2d: fullPathForFilename: No file found at bt_com.png. Possible missing file.

输出里面确实有图片没有找到,但是在cocosstduio里面就是可以看到图片的,好奇怪啊!cocosstudiio里面也没有设置什么图片路径的地方。

请问大哥,我该怎么解决这个问题呢,无从下手啊?

额~~~问题解决了,我之前把cocosstudio发布资源的res整个文件夹一起拷贝到Resource目录下,然后加载“res/MainScene.csb”就会出错,但是我把res里面的内容拷贝到Resource目录,然后加载“MainScene.csb”就没有问题了,但是总觉得这个问题非常的奇怪,难道cocosstudio导出的文件都只能放在Resource的更目录吗,不能有2级目录吗,很是奇怪!

可以有二级目录,在AppDelegate::applicationDidFinishLaunching()中设置二级目录路径FileUtils::getInstance()->addSearchPath(“res”);就可以了。

恩,谢谢,我小白,刚刚学习,谢谢指导!

楼主请问 CSLoader 这个需要导入头文件?直接写好像不行吧

楼主求解怎样获取到ui中的某个控件

要自己写一个方法来获取节点
Node* G_SeekNodeByName( Node* root, const std::string& name)
{
if (!root)
{
return nullptr;
}
if (root->getName() == name)
{
return root;
}
const auto& arrayRootChildren = root->getChildren();
for (auto& subWidget : arrayRootChildren)
{
Node* child = dynamic_cast<Node*>(subWidget);
if (child)
{
Node* res = G_SeekNodeByName(child, name);
if (res != nullptr)
{
return res;
}
}
}
return nullptr;
}

在cocos2dx的官网中也有介绍的http://cn.cocos2d-x.org/tutorial/show?id=1946

我的已经写了怎么不行呢

同样的问题。没有报错,但还是显示不出来。。。。

suffix = csb
textureSize = 3
classname = Node
size = 8
classname = Button
Scale9Sprite capInsetsInternal > originalSize
Scale9Sprite capInsetsInternal > originalSize
Scale9Sprite capInsetsInternal > originalSize
callBackName cannot be found
size = 0
child = 0x7c32d800
classname = GameMap
cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from to .
size = 0
child = 0x7cb1f400
classname = Sprite
size = 0
child = 0x7c339000
classname = Sprite
size = 0
child = 0x7c339600
classname = Sprite
size = 0
child = 0x7c339c00
classname = Sprite
size = 0
child = 0x7c33a200
classname = Text
callBackName cannot be found
size = 0
child = 0x7c33bc00
classname = ProjectNode
filePath = Layer.csb
textureSize = 1
classname = Node
size = 1
classname = Sprite
size = 0
child = 0x7cb7ee00
size = 0
child = 0x7cb7ea00
2015-10-13 18:51:35.369 ConnectGame-mobile cocos2d: surface size: 960x640

用了cocos自带例子MissionSelect,载入后又是这个样子

就是资源路径的事,放在根目录下没问题

资源找不到的话log里会有错误信息,我这里没报错

你可以试一下,放到根目录下,csb里貌似没有资源路径的配置,读的就是当前,没有资源就会默认设置成空,没有任何报错

终于找到答案,感谢楼主