-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touched = [touches anyObject]; CGPoint location = [touched locationInView:self.view]; SKAction* moveAction = [SKAction moveToX: location.x duration:0.0]; [player runAction: moveAction]; }
However, it's preferable to use locationInNode. If we want the spaceship to move in all direction yet we use locationInView, the app will exhibit this same error: http://stackoverflow.com/questions/21948027/skaction-moveto-goes-up-when-should-go-down
CGPoint location = [touched locationInView:self.view] SKAction* moveAction = [SKAction moveTo: location duration:0.0];
Though the spaceship's X will move accordingly to your touch, the spaceship's Y will not follow your finger movements.
To rectify that flaw, get the location from SKScene's view (self) instead of the UIView's view (self.view), then message that view to touched object's locationInNode instead of locationInView
CGPoint location = [touched locationInNode:self]; SKAction* moveAction = [SKAction moveTo: location duration:0.0];
Happy Coding! ツ
No comments:
Post a Comment