TheCrock Posted November 29, 2020 Share Posted November 29, 2020 I have this slice of code which works but is throwing an error in the console. Uncaught type error. Cannot read property of x at undefined. I am using the game loop to move a sprite on its x and y axis. The code works but i get an error and I would be interested to know why. Also when i try to introduce, let state = play; so i can change the call that requests the play(); function to state(); my code stops working. I would like to be able to change the value of state so i can change which function I call by changing the value of state variable. Does any wise member know where i am going wrong? gameLoop(); function gameLoop() { requestAnimationFrame(gameLoop); //Update the current game state: play(); //Render the stage renderer.render(stage); } function play() { explorer.x += explorer.vx; explorer.y += explorer.vy; } Thanks guys. Quote Link to comment Share on other sites More sharing options...
Horizonicblue Posted November 29, 2020 Share Posted November 29, 2020 6 hours ago, TheCrock said: Uncaught type error. Cannot read property of x at undefined. I guess in this case you have not defined explorer properly, so when you do explorer.x += explorer.vx; it must be throwing error Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.