Hopefully somebody will answer this lol, Ive made a couple platformers using python and it makes no sense to use ‘this.width’ here instead of ‘canvas.width’ to me either.
i think this one is that the postion a of the little player blob cant be smaller than the width of the player rectangle itself ? otherwise half the blob would be off the screen ?
I think you’re correct TheKDog. The next step is to set the boundary so that the player doesn’t exceed the right edge of the canvas using an If statement with this.position.x >= canvas.width - this.width * 2
This step is referring to the left edge of the screen. I believe the player class position is the top left corner of the box, the coordinate grid starts at the top left of the canvas, by checking if (this.position.x < this.width), you’re ensuring that the box never approaches closer than one player width of the left edge of the screen. The following step’s limit is if (this.position.x >= canvas.width - this.width * 2), which would put the left edge of the box 2 box width’s away from the right edge of the canvas (so 1 width away from the right edge of the box).
If you wanted to let it get flush with the edges, this step’s condition would be if (this.position.x < 0)
this.width seems to be a flexible version of canvas.width thanks to proportionalSize() which we created earlier on in this project. We are using an if statement of this.width in order to not allow the player character go beyond canvas width even if we change the window size of the browser.