如何在TouchesMoved中获得最后的触摸?

时间:2011-02-28 08:23:09

标签: objective-c cocos2d-iphone touch

我正在使用cocos2d。如何在ccTouchesMoved中获得最后的触摸?

2 个答案:

答案 0 :(得分:1)

在ccTouchesBegan中添加全局变量

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

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

答案 1 :(得分:0)

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

你可以这样做:)