CCLayer with gestures (TAP,DOUBLE TAP, SWIPE supported) IOS (Android should also work)

Thanks for sharing :slight_smile:
I just checked my game Quadro! and it’s still working but i will update XTLayer with your code :slight_smile:

Justin Hawkwood wrote:

I was using a function from XTLayer:
And today it started returning a negative value. For me I was using it to block accidental double taps, which thus meant the app became completely unresponsive. I opted to switch from a long to a double:
And the problem is fixed, at least for a couple years. :wink:
I did not actually use the XTLayer, so I didn’t update the class itself, but I thought I would put this out there for anyone else where this suddenly stopped working.

Thanks Edwin for sharing. It saved a lot of my time :slight_smile:
Edwin van Poeijer wrote:

I’ve written a simple gestures extention for cclayer.
At the moment swipe, tap and double tap are working :slight_smile:
For those interested or looking for a class like this, i have attached it to this message.

any chance this will work on Windows Phone 8.?
will try it out as soon as I have a chance…

Hi Edwin,

Just wondering if you are going to add any “pinch” functionality and maybe any scrolling left to right, up/down, etc.

Thinking like how you can scroll with one finger on ios devices.


HI… i have touches not in a layer but in my hero sprite class by doing CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0); . So, I have CCtouchesBegan, Moved and ended functions in the hero class and it works fine. If I have to make this XTLayer work what I would have to do extra to make it work. All the layer class have XTLayer as base class. thx.

Well using XTLayer this means that the layer will receive the touch events. Not your sprite. It is also not a great idea to have these events on a sprite. Your layer should always be doing this work. At least under any circumstance that I can think of right now. There was some discussion about this a while back, search the forums a bit.

i solved it by copying all the relevent functions and variables from XTLayer onto my player class and works fine now… i am just working how to figure out multi touch with it… seems to working fine… thanks

This is wrong behavior though.

why so? cos it might clash with other layer delegates??

well you are not subclassing correctly, either.

Has anyone updated this for V3 alpha yet?

long Game::millisecondNow()
     struct cc_timeval now;
     CCTime::gettimeofdayCocos2d(&now, NULL);
    return (now.tv_sec * 1000 + now.tv_usec / 1000);

This code can be overflowed. It must be fixed like below.

long long Game::millisecondNow()
     struct cc_timeval now;
     CCTime::gettimeofdayCocos2d(&now, NULL);
    return (now.tv_sec * (long long) 1000 + (long long) now.tv_usec / 1000);

Any fixes for XTLayer to work on 3.0rc0?

Thanks for the share.

I have updated class for v3. If anyone need for it here is the file: (3.6 KB)


thank you very much. You rock!

When i compile the code then gets the 2 error for both schedule_selector
this->schedule(schedule_selector(XTLayer::tapHandler), (this->_xtDoubleTapTime / 1000), 1, 0);

Error 1 error C2440: ‘type cast’ : cannot convert from ‘void (__thiscall XTLayer::* )(cocos2d::CCObject *)’ to ‘cocos2d::SEL_SCHEDULE’

Error 2 error C2440: ‘type cast’ : cannot convert from ‘void (__thiscall XTLayer::* )(cocos2d::CCObject *)’ to ‘cocos2d::SEL_SCHEDULE’

Thanks in advance for any Help

1 Like

This is great. Thank You.

But, can you explain how to detect long touch ?
I try this code and what I find is : if you touch the layer long enough, the xtLongTapGesture function will called when touch ended. Its a long press isn’t it? but what about a long touch ?

I want to call xtLongTapGesture function continiously as long as the layer touched.
Can we do that?



I have found the solution. You just have to use Action on this.

Thanks dear, this was much Needed

change tapHandler parm, to float dt.