Sign in to follow this  
TheCrock

uncaught type error in game loop

Recommended Posts

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.

 

 

 

 

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.