[cocos2d-x 3.0] setTouchEnabled doesn't seem to work?

[cocos2d-x 3.0] setTouchEnabled doesn't seem to work?
0.0 0


Perhaps I’m doing something wrong, but I’ve read in a number of places to get touch working on a layer you need to call setTouchEnabled(true) in the layer’s init() method. Then override ccTouchBegan() and any others you needs. I have done both of these but ccTouchBegan() is never called.

I can only get it to work by also adding the layer to the touch dispatcher like this (after calling setTouchEnabled in init()).

CCDirector::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);

I was under the impression that setTouchEnabled should be enough and the layer should be added automatically to the touch dispatcher for you?


In 3.0, setTouchEnabled(true) will register onTouchesEnded by default.
If you prefer using ccTouchBegin ccTouchEnded etc, you can setTouchMode(Touch::DispatchMode::ONE_BY_ONE)