簡體   English   中英

適用於iOS的Cocos2d。 如何確定觸摸已結束?

[英]Cocos2d for iOS. How to determine that the touching has ended?

如果在觸摸屏幕(或按下主屏幕按鈕)時出現通知(即UIAlertView), ccTouchEnded在游戲層中調用ccTouchEnded ,但觸摸已經結束。

我如何確定觸摸何時結束?

查看有關UIResponder的Apple參考:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIResponder_Class/Reference/Reference.html

你可能想要

touchesEnded:withEvent:

希望這可以幫助 :)

-使您的場景符合CCTargetedTouchDelegate協議- CCTargetedTouchDelegate下行添加到場景的init中:

[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];

-實現以下功能:

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
 {
   return  YES;
 }
 -(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
  {
    //here touch is ended
  }

您應該實現ccTouchesCancelled 只要觸摸事件中斷,就會發生這種情況。

只需檢查您有多少觸摸物體即可。

if([touches count] == 0)
{
  //NO TOUCHES
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM