Discuss Scratch

JachiiStudios
Scratcher
23 posts

Player ***somehow*** switches layers after dying and respawning

So i'm working on a platformer https://scratch.mit.edu/projects/976977265/ and i'm currently working on the death system. For drawing stuff i use a weird hybrid of stamp and sprite-based drawing, i update the sprite's positions using broadcasts and move them to front every time as if it was stamped, just makes it easier to order the layers correctly. Ironically enough, the layers are not ordering correctly, making the player go in front of everything else after dying and then respawning, but then fixing itself after pressing the green flag and i'm completely stumped. All of the ordering is done each frame and the same code is used before and after respawning, so i really don't know what could be causing this. I think my code is pretty self-explanatory, but if you want to help out and don't understand why i did something some way and how it works, please feel absolutely free to ask. thanks in advance.

Last edited by JachiiStudios (March 22, 2024 23:07:48)

Cat_behind_Laptop
New to Scratch
10 posts

Player ***somehow*** switches layers after dying and respawning


Hello! in the sprite - PlayerVis you just need to remove this block everywhere: \[
stop [other scripts in sprite]
and in the broadcast block - PlayerDraw replace this block:
go to front
with:
go back (1) layers
IMPORTANT: I ​​fixed the error in layers, but I don’t know how
it can affect other things, so I advise you to create a copy of
the project before fixing the error

JachiiStudios
Scratcher
23 posts

Player ***somehow*** switches layers after dying and respawning

Hey, i do not see how that would work. The “go to front” is there just like any other visible sprite, and if it wasn't there, let alone a go BACK one layer, it would show behind everything else which is NOT what i want. The stop other scripts in sprite happens only whenever a new animation plays, and it makes sure that any other animations stop playing, i don't see at all how that would change the layering.
Malicondi
Scratcher
1000+ posts

Player ***somehow*** switches layers after dying and respawning

JachiiStudios wrote:

Hey, i do not see how that would work. The “go to front” is there just like any other visible sprite, and if it wasn't there, let alone a go BACK one layer, it would show behind everything else which is NOT what i want. The stop other scripts in sprite happens only whenever a new animation plays, and it makes sure that any other animations stop playing, i don't see at all how that would change the layering.
They mean to in the player sprite, to add a “go back one layer”. The problem is, that since the player sprite's layering is getting messed up because when it stops it's scripts, it goes to the back layer because all the other sprites go to the front layer before them, resulting in the player doing it's scripts last, and since it's script is to go to front, and it's doing it last, it ends up in front of the background.

You can simply fix this by adding a “go back one layer” after the go to front, and it's layering stays correct.

post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.

coming soon :)


Cat_behind_Laptop
New to Scratch
10 posts

Player ***somehow*** switches layers after dying and respawning

JachiiStudios
Scratcher
23 posts

Player ***somehow*** switches layers after dying and respawning

Malicondi wrote:

JachiiStudios wrote:

Hey, i do not see how that would work. The “go to front” is there just like any other visible sprite, and if it wasn't there, let alone a go BACK one layer, it would show behind everything else which is NOT what i want. The stop other scripts in sprite happens only whenever a new animation plays, and it makes sure that any other animations stop playing, i don't see at all how that would change the layering.
They mean to in the player sprite, to add a “go back one layer”. The problem is, that since the player sprite's layering is getting messed up because when it stops it's scripts, it goes to the back layer because all the other sprites go to the front layer before them, resulting in the player doing it's scripts last, and since it's script is to go to front, and it's doing it last, it ends up in front of the background.

You can simply fix this by adding a “go back one layer” after the go to front, and it's layering stays correct.

The problem is that the player doesn't go to front after the other sprites do, they all change layers every frame and the order they change their layers does not change, and THAT is the part i'm confused about.

This is the script that updates the positions and layers of everything:
when I receive [StartLoop v]
forever
broadcast [PlayerTick v]
say [^^^ This just updates the physics]
broadcast [LevelBGDraw v]
say [^^^ Moves the level background's position and sets layer to front]
broadcast [PlayerDraw v]
say [^^^ Moves the player's (visual) position and sets layer to front]
broadcast [LevelDraw v]
say [^^^ Moves the level's (visual) position and sets layer to front]
broadcast [LevelFGDraw v]
say [^^^ Moves the level foreground's position and sets layer to front]
end

This script is stopped when the player dies and then re-enabled after 2 seconds (and a SICK camera animation)

Seriously, what could be causing this?
Also, if i added a “go back one layer” that would achieve the same result as if i changed the order of the blocks so that PlayerDraw is broadcasted before LevelBGDraw, which is either way not what i want
Malicondi
Scratcher
1000+ posts

Player ***somehow*** switches layers after dying and respawning

JachiiStudios wrote:

Seriously, what could be causing this?
Also, if i added a “go back one layer” that would achieve the same result as if i changed the order of the blocks so that PlayerDraw is broadcasted before LevelBGDraw, which is either way not what i want
i wasn't referring to the stop scripts in player sprite, I was talking about the collision sprite. But the real issue is that when the player dies it broadcasts the level and the start loop at mismatched times, the fix is just to add a “wait 0 seconds” before it broadcasts start loop.

post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.

coming soon :)


JachiiStudios
Scratcher
23 posts

Player ***somehow*** switches layers after dying and respawning

Ohh, i see, thank you! It seems to work now!

Powered by DjangoBB