1
我有一個精靈,我想通過使用我的手指移動屏幕〜拖動來移動它。 我希望我的精靈能夠隨着速度移動,這意味着不會像我的手指移動那麼快。如何使用CCTouchMoved在Cocos2d中以速度/速度拖動CCSprite?
它看起來像這個視頻:http://www.youtube.com/watch?v=Vair3CIxZEw(從0:12到0:53)
這是我ccTouch代碼。我怎樣才能修復,讓它移動看起來更順暢?
謝謝!!! :)
簡單地返回TRUE
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
return TRUE;
}
和
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
CGPoint translation = ccpSub(touchLocation, oldTouchLocation);
if (CGRectContainsPoint(_car.boundingBox, touchLocation)) {
CGPoint newPos = ccpAdd(_car.position, translation);
_car.position = newPos;
}
}