UPDATE: I have solved the problem, and figured out a more simplified way to do this then the answer provided. My solution was to make the velocity of the SP
In your thuchesBegan
and touchesMoved
store the touch location as the "target". In the update
then check the position of your ship and reset the xVelocity
to 0 if the ship has reached/passed the target.
Since you are only interested in the x coordinate you could also store just touchLocation.x
. You can also reverse the velocity but I think that would look strange. Note that if the user moves the finger again, your ship will start moving again because the touchMoved
will be triggered again.
On a side note, within touchesMoved
you are also setting the shipLeft
property but this is not set in your touchesBegan
. If this property is used elsewhere you should sync its use.