Learn Intermediate OOP by Building a Platformer Game - Step 31

I have solved this step, but I am confused on the solution. How will the program know it’s referring to the canvas width and not the player width when using this. ?

Step 31

The final condition you need to add inside the Player class is to ensure that the player stays within the boundaries of the canvas screen and doesn’t move too far off to the left.

Create an if statement, to check if the player’s x position is less than the width.

if (this.position.x < solution here) {
      
    }

can you give the link to the step?

1 Like

canvas.width is the canvas width, and it’s not linked to the player object, that’s how it can distinguish the two

1 Like

So for the solution, are we calling the width of the player?

Yes, you are comparing the player’s x position to the player’s width. The lesson just wants to ensure that there is a player-sized gap between the left side of the player, and the left edge of the canvas.

1 Like