Unit 3 - Interactive Animations and Games ('21-'22) Lesson 16 - Sprite moves to top corner

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

Link to the project or level: [Game Lab - Code.org]
What I expect to happen: [Student wants sprite "ship1 to appear in center of screen when run is clicked]
What actually happens: [sprite goes to the top left]
What I’ve tried: [I tried changing numbers, but I will be honest, I can’t figure it out]

Welcome to the Teacher Forum!
If you watch quickly the ship does appear in the center and then travels to the upper left because of the code currently in lines 22-25 where the WorldMousex is used. (That command does this: returns the x coordinate of the mouse and the mouseX values are limited to the size of the display area. The default display area is 400 pixels x 400 pixels and the upper left corner is (0.0).)

The code, as it is now, divides that mouse position by 5 and sets the x and y velocity to that number. It’s moving diagonally because both x and y are being changed. I am not clear on what the purpose of that code is, but maybe it needs to be inside a conditional and only happen under certain circumstances.

Hope this helps.
Code On!

I think the default location is 0,0 so thats why the sprite goes there. How can I give the sprite a location to start?

If you go to " Unit 3 - Interactive Animations and Games ('21-'22)"
Lesson 16 activity 9 b and c, you can see the sprite appear in the top left corner when you run the app. How can you make it start in the center of screen?


In both your example and this one with the bee, the sprite is trying to find the mouse. Until you put the mouse on the screen (somewhere on the grid), World.mouseX and World.mouseY are 0 by default.

You could conditionally position the sprite based on that. In this example, I have a conditional check for world.mouseX. If it is zero, I set the coordinates of the sprite to be 200, 200.



Thank you
that is exactly what I was looking for.