[Resolved]Bug in cc.Node.js

Hi,

I think there’s a bug in addChild method, when I addChild same Sprite more then once, it draws more then once, then I try to removeChild it removes one of it but the display never removes from screen, after removing if you call node.getParent() it returns null. But the sprite or node is still drawing…

Problem causes from there’s no control of parent in addChild method. I node must have one sprite in theory, so I think addChild should be like that

addChild: function (child, …)
{


.

//Warnings etc.

var parent = child.getParent();
if (parent != null)
{
parent.removeChild(child);
}

//insertChild, setParent and other things…
.


}

did you addTargetedDelegate to your sprite?
tyr add a line “cc.Director.getInstance().getTouchDispatcher().removeDelegate(this);” in your sprite’s onExit()

Hi,

which version are you using? this bug was fixed some times ago

I’m using “Cocos2d-html5-v2.1” non-minified version for development…

Hi,

When you try to add the same child twice, a warning will be throw, the game won’t freeze or crash, but will continue to work

Thanks for the bug report, this should fix it