我应该使用什么方法来平滑地移动响应触摸的精灵?我正在使用CCMoveTo方法,我的触摸的持续时间和位置是。我的精灵移动,但它(精灵)跳到使其跳跃的位置。我希望精灵(一个可由用户控制的精灵)在屏幕上拖动时跟随我的手指。提前谢谢你:)
-达斯汀
*编辑
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
return YES;
}
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [self convertTouchToNodeSpace: touch];
//[player stopAllActions];
//[player runAction: [CCMoveTo actionWithDuration:.1 position:location]];
player.position = location;
}
这是我将精灵直接设置为位置后的代码。
试试这样...
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
sprite.position = location;
}
在 touchMoved 中,直接设置精灵的位置,而不是让 CCMoveTo 执行此操作。