Lesson 27 Background and Sprite issues

[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: [Start screen appears and user clicks z. The second screen appears and the sprites begin to appear on the screen.}
What actually happens: [The sprites are appearing on the start screen]
What I’ve tried: [rearranging code in numerous ways]

It seems that your student doesn’t use groups (which will be the main focus here).
How to fix this problem you may ask? Well, it’s pretty simple, just follow these steps.

#1. Cut Out The Clutter. What I mean by this is to delete the functions regarding the background and other code relating to it, since this will be futile later on.

#2. Create a group for the backgrounds, same with the game sprites.

var bg = createGroup();

var sprites = createGroup();

#3. Next, you want to add all the sprites to the selected group just like this.

bg.add(court)

sprites.add(player);
sprites.add(hoop);
sprites.add(block1);
sprites.add(block2);
sprites.add(chaser);
sprites.add(basketball);

#4. Do you know those parentheses in the drawSprites();? Well it’s used for drawing groups, so in those parentheses put the name of the group there then, go to the stage where it’s the game and put drawSprites(bg); and drawSprites(sprites); Keep in mind that this has to go in order | background → the sprites.

drawSprites(bg);
drawSprites(sprites);

This concludes this section.
–EXTRA STUFF THAT I FOUND PROBLEMS WHICH YOU MIGHT PROBABLY WANNA FIX–

One of the problems I found is that this also happens when the score is above 38, to fix this issue you must add “court_2” to the “bg” group.

if (score > 38) {
   bg.add(court_2);
}

If you did not understand anything, I will give you the link and mark the changes with comment blocks.


I hope this has helped you a lot!

@tcreager,

Looks like you might have figured it out? Please check in again if you are still struggling to get it to work or need additional help!

Mike

Thank you so much. This was very helpful. I am learning along with my students, so thank you again!

Hi - Yes, we were able to overcome the problem. Those background changes can be tricky. Thank you for responding!