Tell us what’s happening:
I am sill getting “Sorry, your code does not pass.”
There is clearly something I am doing wrong. Any ideas?
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const animate = () => {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, canvas.width, canvas.height);
player.update();
if(keys.rightKey.pressed && position.x < proportionalSize(400)) {}
}
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (iPad; CPU OS 18_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/131.0.6778.154 Mobile/15E148 Safari/604.1
Challenge Information:
Learn Intermediate OOP by Building a Platformer Game - Step 46
1 Like
I am being asked to:
Inside the animate
function, create an if
statement where the condition checks if the right key was pressed and the player’s x
position is less than proportionalSize(400)
.
I feel like I am clearly doing this but I am still being told my code doesn’t work.
Hi. You’re missing something to indicate that position x is the player’s position x.
I used player.position.x and it worked. In this case, why would I need to do that?
player
class has the state position
and the state have x
property defined in it.
1 Like
So correct me if I’m wrong. Within the player class you would use this. Outside of the class you essentially have to clarify it by placing player. ?
Within the player class you have defined it. Now when you need to use it, you need to get it by
class.state.prop
Means player.position.x
1 Like
Got it! Thanks for the clarification.
1 Like