cocos2dx --- Widget 加载 CCNode
2014-06-05 16:25
337 查看
如题。
Widget 有addChild() 与 addNode() 两个方法。
现在我要加载一个粒子特效进去,下图:
最初,我是直接 使用 layout->addChild(particle); Log中有一个断言失败的错误:下图是错误位置
后来换成 layout->addNode(particle);
加载成功,没有断言失败。但在删除掉的时候出错。。。
解决方法有两种:
1、使用addChild()加载,但中间需要间隔一层Widget,如图:
删除时使用
2、使用addNode()加载
同样,删除时需注意改为
Widget 有addChild() 与 addNode() 两个方法。
现在我要加载一个粒子特效进去,下图:
Widget* layout = dynamic_cast<Widget*>(pRoomWidget[roomId]->getChildByTag(10)); CCParticleSystemQuad* particle = CCParticleSystemQuad::create("particleTexture.plist"); particle->setPosition(CCPointZero); layout->addChild(particle);
最初,我是直接 使用 layout->addChild(particle); Log中有一个断言失败的错误:下图是错误位置
void Widget::addChild(CCNode* child, int zOrder, int tag) { CCAssert(dynamic_cast<Widget*>(child) != NULL, "Widget only supports Widgets as children"); CCNode::addChild(child, zOrder, tag); _widgetChildren->addObject(child); }
后来换成 layout->addNode(particle);
加载成功,没有断言失败。但在删除掉的时候出错。。。
解决方法有两种:
1、使用addChild()加载,但中间需要间隔一层Widget,如图:
<span style="white-space:pre"> </span>CCParticleSystemQuad* particle = CCParticleSystemQuad::create("particleTexture.plist"); particle->setPosition(CCPointZero); Widget* pNode = Widget::create(); pNode->setPosition(CCPointZero); pNode->addNode(particle); layout->addChild(pNode);
删除时使用
<span style="white-space:pre"> </span>layout->removeAllChildren();
2、使用addNode()加载
<span style="white-space:pre"> </span>CCParticleSystemQuad* particle = CCParticleSystemQuad::create("particleTexture.plist"); particle->setPosition(CCPointZero); layout->addNode(particle);
同样,删除时需注意改为
<span style="white-space:pre"> </span> layout->removeAllNodes();
相关文章推荐
- cocos2dx --- Widget 载入中 CCNode
- [cocos2dx:日常学习]场景预加载
- cocos2dx ListView 动态加载(代码)
- cocos2dx 2.1.4 CCNode解析(重点:局部坐标转换机制分析)
- cocos2dx3.2开发 RPG《Flighting》(三)从Excel表中加载需要的数据
- cocos2dx在vs2013加载项目失败(针对路径更改问题)
- cocos2dx3.2 异步动态加载
- 关于cocos2dx widget窗口中的关闭按钮 删除自身 的时候崩溃bug
- Cocos2dx android下异步加载骨骼动画崩溃问题
- Android中AppWidget加载流程(二)
- 关于cocos2dx widget窗口中的关闭按钮 删除自身 的时候崩溃bug
- 创建cocos2dx项目时,加载已有游戏时不能真机测试的问题
- cocos2dx在模版中新建类后无法加载头文件问题
- cocos2dx Android 使用WebView来加载网页
- cocos2dx lua文件的加载问题
- cocos2dx 3.8加载cocos studio csb文件
- Cocos2dx之进度条使用,异步加载资源进缓存
- cocos2dx加载网络动态图片资源
- Cocos2dx-3.x CSLoader 加载
- cocos2dx 加载cocostudio创建的exportjson文件 不同图片之间会有黑线问题解决方法