我使用以下代码在我的应用程序中移动一个精灵:
- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
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);
CGPoint newPos = ccpAdd(self.position, translation);
self.position = newPos;
}
它工作正常,但是当取景器在屏幕上时,精灵会移动。
我想要实现的是滑动后的某种动力,例如在 iOS 中的内置应用程序中。
谁能给我一个提示如何做到这一点?