Getting a Sprite to "Destroy" to show new level in Gamelab

Hello All,

I am an instructor new to and i have a couple students making projects in here independent of the set curricula. Both students technically have more Gamelab experience than I do! I’ve done more “real world” coding.

My student and I can’t figure out how to advance to the next level in this project. The idea is that once the character walks through (to the right) and touches the trophy, a You Win screen appears and then, once you click on that, the background sprite is ‘destroyed’ and now the character is on a different level (Different sprite bg).

Any suggestions would be great! Thank you, Bridget

Link to the project or level: [replace with link to the curriculum or get the “Share” link to a project]
What I expect to happen: [replace with a detailed description of the behavior you’re trying to create]
What actually happens: [replace with a detailed description of what actually happens when the code runs including any errors or unexpected behavior]
What I’ve tried: [replace with a detailed description of what you’ve already tried to do to solve the problem]

@batchcooley.bridget ,

Looks like a fun game! I can see they have learned quite a bit.

This suggestion should help them, but if they get down the road and it isn’t working, feel free to check back in.

I would suggest they create a level variable at the top of the game. For example: var level=1;

Then, inside the draw loop, there could be a conditional statement checking for the level. If level == 1, { ... }

The background and other elements you want to change could be where the … is now.

That could be expanded to be an if else block and if the level is 2, it could have a different background etc.

I hope this is enough to get them started. Have them give it a shot and see if they can add a 2nd level, but check back in if you need a pair of eyes on it.

Good luck!


1 Like

Thank you, Mike! He and I looked through this today and we shall see how he’s able to build on it! I’ll put in an update.

1 Like

Helllo again! We have made some progress. The level DOES change, but now I think the background is not re-drawing properly because we see the sprites every single re-draw. It’s a cool effect, but not desired. If anyone has a chance to take a look at this, that is much appreciated! Thank you!


Glad the level change is working for you. The sprites are creating a trail because the background. is not being drawn consistently. The way the code is written, the drawSprites is only being drawn when the mouse is clicking the “win”. To fix this, the first step is to change the beginning value of level from 2 to 0. Then, change the mousePressedOver(win) actions ONLY to set a new value of level = 2. Then create another if statement (not nested) so that if level == 2, the bg2 is visible and the 1st background is hidden. Hope that makes sense. Good luck!

1 Like

Hi, thank you Michelle! I am so proud of the student, he was able to work this out himself, actually, before I could get back to him! I appreciate your post.

Of course this leads to my next question. Getting his sprites to reset into the same place is leading to issues. I am trying to think through how to reset the sprites’ positions when the level changes. He had the idea of creating a function so that maybe the function can just be called, and then the positions could be reset. This makes sense to me but we aren’t getting it to work! Ack, another call for help! Thank you everybody!

Has he tried to implement this yet? What are the problems?

I assume he is trying to change the x and y values of the sprites? The trick would be determining when to do that.

A function would be a good way to do it.

Let us know once he tries if it isnt working.


That’s exactly where we are at. I can’t quite figure out why his functions won’t work :frowning:

Ok. Maybe I’m missing something because when he passes the first level, he has it coded so if you click on “win”, it changes the background and moves the kid back to the left and it seems to be working … maybe he figured it out?

If not, let me know.



Well, we coded in that “kid” x,y position in the particular conditional statement he has there. But he (we) had wanted a function so he could set those x, y coordinates just once and then re-call them at each level since there are a lot of sprites to be re-typing the coordinates over and over (or re-pasting, but you know a lot of code).

In trying different aspects / placements of the functions, I wasn’t successful. I just don’t know If i don’t understand properly, or if there’s some sort of thing i am missing. Thanks!

Ok… I may have to see what he tried to be able to see why it’s not working.

Here’s a remix I made where I created a function called resetSprites that essentially does what your game does when clicking on the finish box.


Hello! This looks very interesting. Thank you for the quick reply and I will report back on how it goes working with the student. We are wrapping up for the semester but I would like us to come back to these projects we are doing in a couple months and finalize them!

1 Like