Discuss Scratch

FistMotag
New Scratcher
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.
ResExsention
New Scratcher
1000+ posts

Make sprite disappear when background changes

Hm… You might use a broadcast just before you switch backdrops:

broadcastswitch_backdrop

And use a receiver in the enemy to flag a local variable:

whenIreceiveswitch_backdropsetbackdrop_switchedto1

whenIstartasacloneforeverifbackdrop_switched=1thendeletethisclone

I might be wrong, though. Can you share your project with us?
FistMotag
New Scratcher
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.
FistMotag
New Scratcher
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
FistMotag
New Scratcher
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
New Scratcher
1000+ posts

Make sprite disappear when background changes

FistMotag wrote:

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…
True-False-Boolean
Scratcher
1 post

Make sprite disappear when background changes

Easy
whenbackdropswitchestoBackdrophide
ResExsention
New Scratcher
1000+ posts

Make sprite disappear when background changes

True-False-Boolean wrote:

Easy
whenbackdropswitchestoBackdrophide

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
New Scratcher
12 posts

Make sprite disappear when background changes

Guys, thank you so much. Had a Eureka moment. It's as simple as making
whenbackdropswitchestoBackdropdeletethisclone
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
Scratcher
1000+ posts

Make sprite disappear when background changes

If you don't like that code, then try this:
WhenIstartasaclonesee note 1 setRoomtobackdropnumbersee note 2waituntilnotbackdropnumber=Roomdeletethisclone
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
Scratcher
100+ posts

Make sprite disappear when background changes

Another method
set countto1foreverifnotbackdrop#=countthensetcounttobackdrop#deletethisclone

Last edited by axisjack (June 17, 2019 21:57:49)

hilo1888881
Scratcher
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
Scratcher
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.

whenbackdropswitchesto any backdropshowwhenthisspriteclickedhide

Add this script to the stop button sprite. hope i helped

Last edited by thelion5000 (Nov. 15, 2020 19:19:29)

TechKid22
Scratcher
500+ posts

Make sprite disappear when background changes

Here is the script:

ifbackground=(insert backdrop number wantedthenhide
lordibel
Scratcher
1000+ posts

Make sprite disappear when background changes

TechKid22 wrote:

Here is the script:

ifbackground=(insert backdrop number wantedthenhide
But he is using clones
hilo1888881
Scratcher
10 posts

Make sprite disappear when background changes

oh ok ty il try and use it!

Badboy179
Scratcher
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
Scratcher
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
Scratcher
34 posts

Make sprite disappear when background changes

FistMotag wrote:

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.
Can you send the link to your project so I can look at the code and help you?
PopularOnScratch
Scratcher
100+ posts

Make sprite disappear when background changes

Badboy179 wrote:

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
Plz don't necropost

Powered by DjangoBB