• cocos2dx --- Widget 载入中 CCNode


    如果说。


    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();



    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    DSP Builder设计一个滤波器
    Modelsim 10.0 对Altera FFT IP 进行仿真
    FPGA内部计算小数
    TIOBE 2012年3月编程语言排行榜:JS超越Perl和Python
    转载 10个新鲜的Ajax相关的jQuery插件
    转载 使用HTML5、CSS3和jQuery增强网站用户体验
    转载 Java堆内存的10个要点
    累 腾讯笔试
    python 浮点数取整
    转载 一个页面重构工程师眼中的“用户体验”
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4868214.html
Copyright © 2020-2023  润新知