cocos studio 加载json文件到场景后重新渲染纹理失败
2017-12-21 15:20
465 查看
如题,由于场景元素多,就用cocos studio搭界面,但是在代码中想对一张图片资源做修改时遇到错误
Sprite* head_warp=(Sprite*)this->created->getChildByTag(10);
进行判断后想修改文理,正常调用setTexture(图片名称)就可以修改文理
例如:head_warp->setTexture("person_head_0.png");
但是这种方法貌似只支持创建的时候就用图片名称创建的才行
后来尝试
Sprite * aa = Sprite::create("person_head_0.png");
head_warp->setTexture(aa->getTexture());
此方法不报错,但是无法修改纹理
考虑到cocos studio会不会根本没有初始化纹理呢
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("person_head_0.png");
head_warp->createWithTexture(texture);
还是不行。。。
那就用从图片获取纹理后再设置试试
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("person_head_0.png");
head_warp->setTexture(texture);
依旧失败。。。
简直叫人绝望了,我都想设置这个图片不可见然后重新创一个了-.-!
要不用ImageView试试,这家伙不是还有个loadTexture方法么,不试白不试,毕竟底层代码看得有点头大
获取:ImageView* head_warp=(ImageView*)this->created->getChildByTag(10);
修改:head_warp->loadTexture("person_head_0.png");
居然就这么好了。。。
Sprite* head_warp=(Sprite*)this->created->getChildByTag(10);
进行判断后想修改文理,正常调用setTexture(图片名称)就可以修改文理
例如:head_warp->setTexture("person_head_0.png");
但是这种方法貌似只支持创建的时候就用图片名称创建的才行
后来尝试
Sprite * aa = Sprite::create("person_head_0.png");
head_warp->setTexture(aa->getTexture());
此方法不报错,但是无法修改纹理
考虑到cocos studio会不会根本没有初始化纹理呢
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("person_head_0.png");
head_warp->createWithTexture(texture);
还是不行。。。
那就用从图片获取纹理后再设置试试
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("person_head_0.png");
head_warp->setTexture(texture);
依旧失败。。。
简直叫人绝望了,我都想设置这个图片不可见然后重新创一个了-.-!
要不用ImageView试试,这家伙不是还有个loadTexture方法么,不试白不试,毕竟底层代码看得有点头大
获取:ImageView* head_warp=(ImageView*)this->created->getChildByTag(10);
修改:head_warp->loadTexture("person_head_0.png");
居然就这么好了。。。
相关文章推荐
- Mac下使用Cocos2d-x Lua加载Cocos Studio到处的Json文件和动画
- Visual Studio 提示某个dll文件(已在Microsoft Visual Studio 外对该文件进行了修改,是否重新加载它)
- Cocos2d-JS 加载CocosStudio场景及触发器
- cocos2d js 读取由cocos studio生成的json格式的配置文件
- Cocos Studio生成Json文件并使用rapidjson获取Json数据
- can not find xxx.json file,或者文件读取失败,请检查后重新编译。
- Mac下使用Cocos2d-x Lua 3.2加载Cocos Studio 1.0beta导出的Json
- 加载cocos studio场景
- android webview 使用js加载json文件失败
- 关于cocos2dx3.0版本,导入cocosStudio UI编辑器的json文件
- 微信小程序—未找到入口 app.json 文件,或者文件读取失败,请检查后重新编译。
- VM222:2 pages/two/two.json 未找到入口 pages/two/two.json 文件,或者文件读取失败,请检查后重新编译。
- Microsoft Visual Studio--- 未能加载文件 %CommonDir%\dte90a.olb。未能找到该文件,因此解决此问题的尝试,请重新安装此程序。
- Cocosd2d-js 使用Cocos Studio生成的Json界面文件
- Cocos Studio生成Json文件并使用rapidjson获取Json数据
- Cocos2d-x 3.9教程:10.使用CocosStudio的UI编辑器从UI文件中加载布局和控件
- OpenGLES加载tga文件为纹理
- 【Cocos2d-x 001】VS2012打开Cocos解决方案显示加载失败
- 记录7.0加载so文件失败:java.lang.UnsatisfiedLinkError: dlopen failed: library "libsqlite.so" not found
- vue.js学习笔记:如何加载本地json文件