开发者

How to get last touch in ccTouchesMoved?

开发者 https://www.devze.com 2023-02-14 08:02 出处:网络
I\'m working with cocos2d. How to get last touch in ccTouchesMove开发者_开发知识库d?Add a global Variable in your ccTouchesBegan,

I'm working with cocos2d. How to get last touch in ccTouchesMove开发者_开发知识库d?


Add a global Variable in your ccTouchesBegan,

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

in your ccTouchesMoved just use startPosition to check whether your hand moved


- (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]; 
}

You can do like that :)

0

精彩评论

暂无评论...
验证码 换一张
取 消