Learn Create Your Own Split Screen

Next Page

It sure looked like our attempt to keep the cat from going too far right was doing nothing.

But the code is doing exactly as we asked, which is that the "x" of the image should not go past the "x" of the canvas.

Consider this:

At the point the cat "x" hits the canvas "x", the rest of the cat is already off the screen. It goes no further, but that's not exactly helpful


The problem is we're comparing the left side of the image with the right side of the canvas.

We need to compare the right side of the image.

If the left side is given by

x_pos
Then the right side is given by
x_pos + MyImg.width