Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Make sprite disappear when background changes
- FistMotag
-
12 posts
Make sprite disappear when background changes
I'm making an RPG that changes backgrounds when you touch the edge of the screen. There are about 50 backgrounds (this is important).
Basically, when you walk to the edge and subsequently change the background when there are still enemies on-screen, I need the enemies to disappear.
Here's the catch: sometimes, there will be multiple of the same enemies on-screen (I'm using clones) and the adjacent room/background will spawn more of the same enemy.
The trouble I'm having is making the enemy clones in your current room vanish when you change environments but create clones when entering an adjacent room that utilizes the same enemies.
Let me know if that makes sense.
P.S.: There is already a LOT of code for the enemy so it would take me a very long time to implement it here. The enemy is complete; I only need it to do what I described above
Thanks.
Basically, when you walk to the edge and subsequently change the background when there are still enemies on-screen, I need the enemies to disappear.
Here's the catch: sometimes, there will be multiple of the same enemies on-screen (I'm using clones) and the adjacent room/background will spawn more of the same enemy.
The trouble I'm having is making the enemy clones in your current room vanish when you change environments but create clones when entering an adjacent room that utilizes the same enemies.
Let me know if that makes sense.
P.S.: There is already a LOT of code for the enemy so it would take me a very long time to implement it here. The enemy is complete; I only need it to do what I described above
Thanks.
- ResExsention
-
1000+ posts
Make sprite disappear when background changes
Hm… You might use a broadcast just before you switch backdrops:
And use a receiver in the enemy to flag a local variable:
I might be wrong, though. Can you share your project with us?
And use a receiver in the enemy to flag a local variable:
I might be wrong, though. Can you share your project with us?
- FistMotag
-
12 posts
Make sprite disappear when background changes
Thanks, I'll give this a shot.
I'll see if I can upload it. It's still very WIP, but the game functions. I've been making it on the desktop version of Scratch because Chrome began to die when the code got too big. Also… I'm still fairly new to Scratch (only started about three months ago), so the code might be… messy, to say the least.
I'll see if I can upload it. It's still very WIP, but the game functions. I've been making it on the desktop version of Scratch because Chrome began to die when the code got too big. Also… I'm still fairly new to Scratch (only started about three months ago), so the code might be… messy, to say the least.
- FistMotag
-
12 posts
Make sprite disappear when background changes
Online Scratch is unable to save my project. It was originally because of one the sound files, but it won't even save after removing it.
Here's a link to the desktop file on my Google Drive.
https://drive.google.com/file/d/1DE_Tw1me85tc2Lh3y4hWOCBtnmKeWyoc/view?usp=sharing
Here's a link to the desktop file on my Google Drive.
https://drive.google.com/file/d/1DE_Tw1me85tc2Lh3y4hWOCBtnmKeWyoc/view?usp=sharing
- FistMotag
-
12 posts
Make sprite disappear when background changes
I've been working all morning on my game. Unfortunately, the script you gave me to try out only partially works. It does delete the clones, but the script continues running for a little too long after loading the next background and deletes half of the clones that are supposed to be in the next room.
- ResExsention
-
1000+ posts
Make sprite disappear when background changes
I've been working all morning on my game. Unfortunately, the script you gave me to try out only partially works. It does delete the clones, but the script continues running for a little too long after loading the next background and deletes half of the clones that are supposed to be in the next room.
Oh.
Deleting the clone should stop the script, perhaps you should add a 3 second wait block to let it cool down between backdrop switches? I'm not sure…
- ResExsention
-
1000+ posts
Make sprite disappear when background changes
Easy
He's using clones. That wouldn't work, because that wouldn't delete a clone. The script has to be under a when I start as clone block. I may be wrong, though. I get stuck in all these coding conventions and I forget to explore other solutions :/
- FistMotag
-
12 posts
Make sprite disappear when background changes
Guys, thank you so much. Had a Eureka moment. It's as simple as making
For every backdrop. Messy, but fast and works flawlessly. Thank you all for the help!!!!
Last edited by FistMotag (June 17, 2019 20:59:35)
- codeman1044
-
1000+ posts
Make sprite disappear when background changes
If you don't like that code, then try this:
2. Make sure this is a local variable for ID purposes (for this sprite only). For more on local variables, see here.
Hope this helps!
1. This should be a new when I start as a clone block. Otherwise, it will freeze the other blocks in the clone's script.
2. Make sure this is a local variable for ID purposes (for this sprite only). For more on local variables, see here.
Hope this helps!
Last edited by codeman1044 (June 17, 2019 21:38:29)
- axisjack
-
100+ posts
Make sprite disappear when background changes
Another method
Last edited by axisjack (June 17, 2019 21:57:49)
- hilo1888881
-
10 posts
Make sprite disappear when background changes
i don't understand how to switch backdrops and make my sprite disappear with it and reappear when i press stop. :c can someone help me plzzzz
Last edited by hilo1888881 (Nov. 14, 2020 21:59:59)
- thelion5000
-
100+ posts
Make sprite disappear when background changes
I don't think stop is a key , is it a button in your game, if it is then add this script.
Add this script to the stop button sprite. hope i helped
Add this script to the stop button sprite. hope i helped
Last edited by thelion5000 (Nov. 15, 2020 19:19:29)
- lordibel
-
1000+ posts
Make sprite disappear when background changes
But he is using Here is the script:clones
- hilo1888881
-
10 posts
Make sprite disappear when background changes
oh ok ty il try and use it!
- Badboy179
-
7 posts
Make sprite disappear when background changes
I have a problem I've made a level but I just realized that I don't like the plain white backdrop but when I add the backdrop my level disappeared how do I fix this





- Badboy179
-
7 posts
Make sprite disappear when background changes
I have a problem I've made a level but I just realized that i don't like the lain white backdrop but when I add the backdrop my level disappeared how do I fix this





- BigBoyStudios798
-
34 posts
Make sprite disappear when background changes
Can you send the link to your project so I can look at the code and help you? I've been working all morning on my game. Unfortunately, the script you gave me to try out only partially works. It does delete the clones, but the script continues running for a little too long after loading the next background and deletes half of the clones that are supposed to be in the next room.
- PopularOnScratch
-
100+ posts
Make sprite disappear when background changes
Plz don't necropost I have a problem I've made a level but I just realized that i don't like the lain white backdrop but when I add the backdrop my level disappeared how do I fix this
- Discussion Forums
- » Help with Scripts
-
» Make sprite disappear when background changes