Smooth movement with touches
What method should I use to smoothly move my sprite that responds to a touch? I am using the CCMoveTo method with the duration and the position of my touch is. My sprite moves but it (the sprite) skips over to the position which makes it jumpy. I want the sprite(one sprite controllable by the user) to follow my finger as it drags across the screen. Thank you in advance :)
-Dustin
*EDIT
- (BOOL)ccTouchBega开发者_JS百科n:(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;
}
That's the code after I set the sprite directly to the location.
Try Like this...
- (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;
}
In touchMoved, set the sprite's position directly instead of getting CCMoveTo to do it.
精彩评论