[英]Double tap Cocos2d Android JAVA
Trying to detect doubletap in Android (Cocos2d Framework). 尝试在Android(Cocos2d Framework)中检测双击。 What am I doing wrong?
我究竟做错了什么?
In ccTouchesEnded i have : 在ccTouchesEnded中,我有:
public boolean ccTouchesEnded(MotionEvent event) {
touchTapCount++;
Lg("Tapcount : " + touchTapCount);
if (touchTapCount == 1) {
Lg("We're in the 1 thingie!");
CCDelayTime delayaction = CCDelayTime.action(0.2f);
CCCallFunc callSelectorAction = CCCallFunc.action(this, "dtreset");
CCSequence a = CCSequence.actions(delayaction,(CCFiniteTimeAction) callSelectorAction);
this.runAction(a);
} else {
if (touchTapCount ==2){
Lg("Oh yeah we got double tap!");
}
}
And I've got the resetter : 而且我有重置者:
public void dtreset(Object Sender){
Lg("Resetted the TouchTapCount");
touchTapCount = 0;
}
My output indicates that the sequence is not runned at all.. So count just gets added, there is no reset after 200 ms... :( 我的输出表明该序列根本没有运行。.因此,只添加了count,在200 ms之后没有复位... :(
As a solution, I decided to use android's own Handler class; 作为解决方案,我决定使用android自己的Handler类。
public boolean ccTouchesEnded(MotionEvent event) {
touchTapCount++;
Lg("Tapcount : " + touchTapCount);
if (touchTapCount == 1) {
// Very important bit of code..
// First, we define a Handler and a Runnable to go with it..
Handler handler = new Handler(Looper.getMainLooper());
final Runnable r = new Runnable() {
public void run() {
// In the runnable, we set the touchTapCount back to 0..
touchTapCount = 0;
}
};
// Now, execute this handler with a delay of 200ms..
handler.postDelayed(r, 200);
} else {
if (touchTapCount == 2){
wasdoubletapped = true;
verifySelectorTypeBeforeRotate(cC, cR, SELECTOR_CROSS);
}
So what this does: detect double tap, by counting the number of taps and resetting that count to zero, 200 ms after the first tap. 因此,它的作用是:通过计数抽头数并在第一次抽头后200毫秒将该计数重置为零来检测双击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.