Sprite set to be at 300, 300 but it is at 0, 0

I have a student who is working on his interactive card. I can see that he wants the axe sprite to appear at 300 x 300 on the grid. It is appearing instead at 0 x 0. I can’t see what he is doing wrong. Help!

Here is a link: https://studio.code.org/projects/gamelab/6kkjwqG_-fRd_HGvBff8e_o3r_abL1xrcgsnTNUqrNs/edit

Hi Eugenie,
This is happening because of the lines of code that are moving the sprite to the mouse’s position:
Axe.x = World.mouseX;
Axe.y = World.mouseY;
These values are updated any time the mouse moves somewhere over the game area. If the mouse moves off the game area, the values don’t change, and if the mouse hasn’t yet been over that area (such as when the project just starts, they both have a value of 0.

You can see the axe move just by moving the mouse around. If it’s important to see the axe somewhere else before the player moves the mouse, you could alter it so that the axe’s position is only updated if the mouse moves:

  if(mouseDidMove()){
    Axe.x = World.mouseX;
    Axe.y = World.mouseY;
  }
1 Like

Thank you!

Eugenie Farrow
Computer Science Instructor
http://www.spokanevalleytech.org/pages/Spokane_Valley_Tech
(509) 558-6508