We know that only you understand and learners don’t. do you care to explain what this ‘this.position.x >= canvas.width - 2 * this.width’ means, especially the - 2
it’s -2 * this.width
. It’s the width of the canvas minus twice the width of this
. I guess it’s a check on the horizontal position to avoid it going too far right, so that the object doesn’t go nearer to the right side than its width. (it’s twice the width because the x,y position of the object is its top left corner)
This is where you need to think about what you’re doing. Keep track of the maths, it’s so important to understanding what you’re actually doing here
You know how big the canvas is, what the width is. You’ve got the function that calculates the proportional width.
So if you plug numbers into that equation, just on paper, which values come back true and which values come back false? Why? (And this applies to all the maths here, plug different values in, see what happens)
thank you, I wish to know and understand much like you do. will I get there ?.. I don’t know, because much of the staff here that you build and the logic that you put together… I don’t think I can do that on my own. you are brilliant people.
thanks, but somehow a personal tutor would help here which I don’t have. whoever said javascript is easy, I don’t know what they were talking about
You also need to understand operator precedence to read it. Which I’m not sure if we are even teaching.
I don’t know why it was written like that, but just reordering it would help a lot in my opinion.
canvas.width - this.width * 2
It doesn’t really help that the code is completely inert. But you can add an instance of the class and call the method at the bottom of the file, just so you can log stuff out and play around with the code in question.
const p = new Player();
p.update();
I made a PR to switch the order of operations.