addTargetedDelegate in 2.2?


#1

Hi all,
I want to enable TOUCH in cc.Node, I found these code from web:

cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 0, false);
cc.Director.getInstance().getTouchDispatcher().removeDelegate(this);

But it did not work in cocos2d-html5 2.2, an error message was given:

Uncaught TypeError: Object # has no method 'addTargetedDelegate' 

Could anyone help?
Many thanks!


#2

Hi Yong,

cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate, cc.Director.getInstance().getTouchDispatcher().addStandardDelegate
and cc.Director.getInstance().getTouchDispatcher().removeDelegate have been private, please use cc.registerTargetedDelegate, cc.registerStandardDelegate and cc.unregisterTouchDelegate instead.
for example:
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, this._touchPriority, true) -> cc.registerTargetedDelegate(this._touchPriority, true, this);

more about the upgrade guide from v2.1.5 to v2.2, please look at:
http://www.cocos2d-x.org/wiki/Upgrade_Guide_from_Cocos2d-html5_v215_to_v22

Regards
David


#3

It works, thank you David.


#4

@ludingping
more about the upgrade guide from v2.1.5 to v2.2, please look at:
http://www.cocos2d-x.org/wiki/Upgrade_Guide_from_Cocos2d-html5_v215_to_v22

the url is not found


#5

Hi,@loong319

I’s sorry, we refactored the document’s directory, please see:http://www.cocos2d-x.org/wiki/Upgrade_Guide_from_Cocos2d-html5_v215_to_v22

BTW, we update the event handler in v3.0, please see this: http://www.cocos2d-x.org/forums/19/topics/45954