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

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

#22

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.


#23

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

Hi,
>
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.


#24

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


#25

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.

Jason


#26

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.


#27

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.


#28

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


#29

This is wrong behavior though.


#30

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


#31

well you are not subclassing correctly, either.


#32

Has anyone updated this for V3 alpha yet?


#33
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);
 }

#34

Any fixes for XTLayer to work on 3.0rc0?


#35

Thanks for the share.


#36

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

XTLayer_v3.zip (3.6 KB)


#37

thank you very much. You rock!


#38

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);
and
this->unschedule(schedule_selector(XTLayer::tapHandler));

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


#39

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?

Thx

[Edited]

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


#40

Thanks dear, this was much Needed


#41

change tapHandler parm, to float dt.