Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all articles
Browse latest Browse all 2748

Change node parent with EventListener

$
0
0

@Donmizzi wrote:

Hi, I have a code like this (TouchObj is a Node):

test = TouchObj::Create("image");
test->retain();
test->setSelectorRelease("testMethod");
Layer_1->addChild(test);

void testMethod()
{
  test->removeFromParent();
  Layer_2->addChild(test)
}

TouchObj has an EventListerner in the onEnter():

  _listener = EventListenerTouchOneByOne::create();
  _listener->onTouchBegan = CC_CALLBACK_2(TouchObj::onTouchBegan, this);
  _listener->onTouchMoved = CC_CALLBACK_2(TouchObj::onTouchMoved, this);
  _listener->onTouchEnded = CC_CALLBACK_2(TouchObj::onTouchEnded, this);
  _listener->onTouchCancelled = CC_CALLBACK_2(TouchObj::onTouchCancelled, this);
  _listener->retain();
  this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(_listener, this);

With this cosa, when I try to change parent, I have an ASSERT in the CCEventDispatcher

CCASSERT(!listener->isRegistered(), "The listener has been registered.");

because isRegistered is true, infact removeEventListener is not called if the object is live.

There is a proper way to manage change parent for a Node with EventListener?

Thank you
Regards
Don

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 2748