【问题标题】:How to get last touch in ccTouchesMoved?如何在 ccTouchesMoved 中获得最后一次联系?
【发布时间】:2011-02-28 08:23:09
【问题描述】:

我正在使用 cocos2d。如何在 ccTouchesMoved 中获得最后一次联系?

【问题讨论】:

    标签: objective-c cocos2d-iphone touch


    【解决方案1】:

    在你的 ccTouchesBegan 中添加一个全局变量,

    CGPoint touchPoint = [touch locationInView:[touch view]];
    startPosition = [[CCDirector sharedDirector] convertToGL:touchPoint];
    

    在您的 ccTouchesMoved 中,只需使用 startPosition 来检查您的手是否移动

    【讨论】:

      【解决方案2】:
      - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
          UITouch *touch = [[touches allObjects] objectAtIndex: 0];
          // The last location you touch
          CGPoint lastLocation = [touch previousLocationInView:self.view];
          // Current location
          CGPoint currentLocation = [touch locationInView:self.view]; 
      }
      

      你可以这样做:)

      【讨论】:

        猜你喜欢
        • 2020-04-08
        • 1970-01-01
        • 2021-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多