Sprite behavior but no code to cause it

I have a student project that is doing weird things. The program acts like there is a __ < __ statement, but there isn’t. Strange… Any help would be appreciated from more educated eyes than mine.

Intent: Mario touches coin, score goes up, coin moves to a new random location.

CS Discoveries, Unit 3, Lesson 20: Student is building the Slide scroller project. He’s modifying it and trying to do a little harder work. However, the code he has written is the same as the ghost /Coin on a previous lesson. The code is exactly the same. However, the sprite (Mario) gets anywhere between 0 - 200 on the “X” and “Y” plane and the coin moves everywhere in a loop. There is no code that we can see that is causing this behavior.

Happening: Mario gets between 0, 200 and the coin moves very fast in whatever (randomNumber) location set for the coin

Tried: moved code, erased code, edited numbers, nothing changes the coin behavior

Lesson link

Thank you!


I edited your post to remove the login information including password as anything on the forum is visible to anyone who wants to see it.

When I clicked on the link, though, I couldn’t access the project. Can you check the settings to see if sharing is enabled?

After that, we are happy to look at it!




Update: Although I did remove your login and password information, I was able to login as your student and view the file.

I believe I have found the issue. All of the sprites are small, but on large canvases. The collision properties will consider the sprites as colliding if any part of the canvas touches any part of the other canvas and since mario and the bullets are small, but their canvases are large, they are constantly colliding, even though it doesn’t appear to be the case on screen.

If you show your student the “crop” button in the animation tab, they can crop each sprite with a single click of the crop button and this problem should be resolved. Cropping resize the canvas to fit the sprite.

It is the purple button on the right side of the screen that looks like a square with an arrow in it.

Hope this helps! Check back in if not.


Mr. Wood you are a genius! That fixed the problem! I am now also smarter about sprites and collision boxes too. Appreciate all your help and problem solving.

Sooooo… how do we now fix the bullets moving at random speeds? We think it’s the math in lines 49 - 54, but not sure how to fix it.
The intent is to get the bullets regenerating and moving at different speeds.

Thank you again!

So right now, lines 46-48 has the bullets moving at a constant speed, but as you mention, lines 49-54 gives them an extra burst of speed when they reach the middle of the screen (x=200). You could delete those lines of code if that is not the intended behavior.

IF you want to regenerate them and give them a random speed, I think the best place to determine their random speed would be after lines 56, 59 & 62. You would probably need a random block there to pick the random speed as they are placed back at x=390.

Good luck!