双击 Cocos2d Android JAVA
Double tap Cocos2d Android JAVA
正在尝试检测 Android(Cocos2d 框架)中的双击。我做错了什么?
在 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!");
}
}
而且我有重置器:
public void dtreset(Object Sender){
Lg("Resetted the TouchTapCount");
touchTapCount = 0;
}
我的输出表明序列根本没有运行。所以只是添加了计数,200 毫秒后没有重置...:(
作为解决方案,我决定使用 android 自己的 Handler class;
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);
}
那么这是做什么的:检测双击,通过计算点击次数并将计数重置为零,在第一次点击后 200 毫秒。
正在尝试检测 Android(Cocos2d 框架)中的双击。我做错了什么?
在 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!");
}
}
而且我有重置器:
public void dtreset(Object Sender){
Lg("Resetted the TouchTapCount");
touchTapCount = 0;
}
我的输出表明序列根本没有运行。所以只是添加了计数,200 毫秒后没有重置...:(
作为解决方案,我决定使用 android 自己的 Handler class;
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);
}
那么这是做什么的:检测双击,通过计算点击次数并将计数重置为零,在第一次点击后 200 毫秒。