Learn Create Your Own Split Screen

Next Page

We just need to flesh out the body of our Move_Towards method. This turns out to be pretty easy.

Recall that our motion is represented by x-velocity and y-velocity components. We move that amount each frame, and taken together it produces an effective motion:

When figuring out the distance from one point to another, we just subtract the x and y coordinates, and that gives us an x-distance and a y-distance.

Plug those distances in as velocities, and presto -- the sprite moves on a path from one precise point to another.