Layering Sprites

Hello, I’m trying to figure out how to help the student get his monster truck sprite to stay on top of his background desert sprite. What do you suggest I do?

Here is a link to his code.

@IMPixel @infinitestasis might be able to help you.

I know how to fix this. The first way is to use groups. He should create a group and then add monster in it. Here’s what I did.


You also have to tell him to put drawSprites(monsterGroup) after the drawSprites(). But then I tried to do this, and it didn’t work. The monster truck wasn’t drawn, and that’s when I saw that monster wasn’t visible.


Here’s the link to the code. - Game Lab

Now it works, but there is another way to fix it. He can place the declaration of his monster sprite after the declaration of the background sprite. So basically just put the lines 4, 5 and 6 between the lines desert.setAnimation(“desert”);
var Jack = createSprite(200, 200);
He should also delete that monster.visible = false; line because that’s the reason he wasn’t seeing the monster.
Here’s the code: - Game Lab

1 Like

Thank you for getting back to me. Since we haven’t used groups it might be better for him to work on layering the monster sprite after the declaration of other background sprite like you suggested. When I change the layering I am still not seeing the monster truck. I have compared our code and I can’t see what you did to make it show up. Can you look at the code I have changed as you suggested and see what I am doing differently?

Oh sorry my bad… I forgot to say when I was writing the answer that I removed a line. In your remix that line is on line 36. As you can see there he moves the monster sprite. That is the reason. Remove the line where he makes the monster’s x position 500 and it should work. (the line 36)

Thank you for your help! Much Appreciated! I will also look into the groups for future reference.