[英]Double tap Cocos2d Android JAVA
嘗試在Android(Cocos2d Framework)中檢測雙擊。 我究竟做錯了什么?
在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;
}
我的輸出表明該序列根本沒有運行。.因此,只添加了count,在200 ms之后沒有復位... :(
作為解決方案,我決定使用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);
}
因此,它的作用是:通過計數抽頭數並在第一次抽頭后200毫秒將該計數重置為零來檢測雙擊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.