Graham Nicol
Graham Nicol

Reputation: 264

Detecting a second touch while holding a first touch in Cocos2d v3 iOS

I'm wanting to be able to detect the following in Cocos2d v3:

A touch is initiated and held, then a second touch occurs somewhere else on the screen. Think of holding with one finger, and tapping with a second.

I've tried to use - (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event but this is only called the first time the second touch occurs, not subsequently.

To be clear, if I hold a touch on the screen and then tap somewhere else, the above method is called. But if I continue holding the first touch and then tap a second time, the above method is not called.

Also, touchBegan: is only called when the first touch occurs (i.e. the initial holding touch) and touchEnded: is only called when all touches are removed, including the initial holding touch.

I'd like to know:

1) How to recognise the above gesture in Cocos2d v3?

2) If 1) isn't possible, would there be a way to do it with my own gesture recogniser, and how would I implement my own gesture recogniser into Cocos2d v3?

Upvotes: 1

Views: 677

Answers (2)

bbm20891
bbm20891

Reputation: 144

if you use void HelloWorld::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) then you get each touch count using pTouches->count();

Upvotes: 0

Graham Nicol
Graham Nicol

Reputation: 264

Turns out by default Cocos2d V3 only responds to a single touch by default.

The solution:

self.multipleTouchEnabled = TRUE;

This means now every new touch will call:

-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event 

And every time a finger is lifted from the screen it will call:

-(void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event

Even if there are other touches continuing.

Upvotes: 1

Related Questions