Using Touch

Using Touch
0.0 0


I’m having problem using the ccTouchEnded method or basically any touch method.

I’ve inherited my class from cocos2d::CCTargetedTouchDelegate

In my init method I’ve set:
My function prototype is declared as below in the class :
virtual void ccTouchEnded;
The function implementation is
void HelloWorld::ccTouchEnded
CCPoint touchLocation = touch~~>locationInView( touch->view() );
touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );

I’ve placed a breakpoint in the ccTouchEnded method but it never reaches that point.
Any idea what I might be doing wrong


ccTouchEnded is for targeted touch delegate.
While setIsTouchEnabled(true) opens the standard touch delegate.
You must override ccTouchesEnded method inherited from CCStandardTouchDelegate in CCTouchDelegateProtocol.h. Take care of the “touches” but not “touch”

About the difference between targeted & standard touch delegate, please read the document on[]=targeted


Ok I’ve got it working. I didn’t check what you mentioned yet. I just changed the function prototype nd defintion to :
ccTouchesEnded(cocos2d::CCSet pTouches, cocos2d::CCEventpEvent)


Are you sure your class is inherited from cocos2d::CCTargetedTouchDelegate, not cocos2d::CCLayer?

In that case, the code


do nothing.

In the initialization of your class, you should invoke:

CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, ...);

Then the function ccTouchEnded in your class will be invoked when a touch event happened.