2012-10-20 14 views
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變量的輸出相同嗎?與CCTouchesBegin問題

回答

1

當觸摸開始時,由於觸摸剛剛開始,顯然沒有以前的觸摸。所以previousLocation和location都是一樣的。

如果您在ccTouchesMoved中運行此代碼,它將按預期工作。

+0

我的應用程序有以下req:我選擇一個精靈在一個點,然後我想要移動到下一個接觸點 – user1761217

0

你只需要在ccTouchesEnded方法中打印你的當前位置。它會給你兩點之間的區別。

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

所以你只需要在ccTouchesBegan方法中獲得previousLoaction