0
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
    CGPoint point1 = [touch previousLocationInView:[touch view]];
    CGPoint point2 = [touch locationInView:[touch view]];

    point1 = [[CCDirector sharedDirector]convertToGL:point1];
    point2 = [[CCDirector sharedDirector]convertToGL:point2];


    pre = point1;
    curr = point2;
    CCLOG(@"the pre location is %@",NSStringFromCGPoint(pre));
    CCLOG(@"the curr location is %@",NSStringFromCGPoint(curr));


}

上面的代码有什么问题?pre 和 curr 变量都给出相同的输出?

4

2 回答 2

1

当触摸开始时,显然没有先前的触摸,因为触摸刚刚开始。所以previousLocation和location都是一样的。

如果您在 ccTouchesMoved 中运行此代码,它将按预期工作。

于 2012-10-20T11:47:49.220 回答
0

您只需在 ccTouchesEnded 方法中打印您的当前位置。它会给你两点之间的差异。

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

所以你只需要进入previousLoactionccTouchesBegan 方法。

于 2012-10-20T17:56:26.033 回答