Learn Create Your Own Split Screen

Next Page

Now we're nicely comparing the left of the image with the left of the canvas:
x_pos > 0
Comparing the top of the image with the top of the canvas:
y_pos > 0
Comparing the right of the image with the right of the canvas:
x_pos+MyImg.width < myCanvas.width
And the bottom of the image with the bottom of the canvas:
y_pos+MyImg.height < myCanvas.height

Try driving the cat around - it's almost perfect.


In fact, it's still going a small amount too far, because we should be comparing with the canvas width minus the step size (10), but it's good enough for now.