Learn Create Your Own Split Screen

Next Page

Now we're going to make the Sprite move towards a destination.

We'll deal with moving as a method separate to pointing, because in some games you'll want the two things to happen together, and in others you might want the sprite to "hover over" to its target.

As before, we'll add a method to our sprite object, but we'll fill in the details later.

MySprite.prototype.Move_Towards = function(target_x, target_y) { // details to come }
We'll make use of that method every frame:
function Do_a_Frame () { ctx.clearRect(0, 0, myCanvas.width, myCanvas.height); // clear the frame jelly.Point_Towards(mouse_x, mouse_y); // tell jelly to point to mouse jelly.Move_Towards(mouse_x, mouse_y); // and move that way jelly.Do_Frame_Things(); // let the jelly do its thing }