Discuss Scratch

zbx1425
Scratcher
6 posts

How to layout sprites in a specific depth order?

I'm trying to develop a game.
In this game there are four layers: Some objects should show above the player object, some should below the player, and some should be the backgrounds, and there's also sprites such as HP indicators should show in the most foreground.
Because the map is scrollable, so each of them is cloned and maybe have four or more instances on the stage at the same time.
So is there anyway to keep them always in the right order?
gotofrontgoback1layers
These blocks do not seem to be very helpful to this problem……
asivi
Scratcher
1000+ posts

How to layout sprites in a specific depth order?

zbx1425 wrote:

I'm trying to develop a game.
In this game there are four layers: Some objects should show above the player object, some should below the player, and some should be the backgrounds, and there's also sprites such as HP indicators should show in the most foreground.
Because the map is scrollable, so each of them is cloned and maybe have four or more instances on the stage at the same time.
So is there anyway to keep them always in the right order?
gotofrontgoback1layers
These blocks do not seem to be very helpful to this problem……

There are not others blocks to solve your issue…
So, what do you think your next step should be, in order to resolve your problem?
asivi
Scratcher
1000+ posts

How to layout sprites in a specific depth order?

If you are cloning all, create those in a logical order.
Finnthebest12
Scratcher
100+ posts

How to layout sprites in a specific depth order?

well you could write a script that, starting at the sprite that should be at the back, sets it to the front when the game is started, then broadcasts a message to the second last sprite(in terms of which sprite should be near the front) then that brings that sprite to the front and broadcasts a message to the next sprite, etc. like the scripts i used to layer some of the sprites ( the car and the roads) in this project: https://scratch.mit.edu/projects/177413383/
zbx1425
Scratcher
6 posts

How to layout sprites in a specific depth order?

Finnthebest12 wrote:

well you could write a script that, starting at the sprite that should be at the back, sets it to the front when the game is started, then broadcasts a message to the second last sprite(in terms of which sprite should be near the front) then that brings that sprite to the front and broadcasts a message to the next sprite, etc. like the scripts i used to layer some of the sprites ( the car and the roads) in this project: https://scratch.mit.edu/projects/177413383/
Thank you!
But in my game the map is scrolling, which means the new instances are created and olds are disposed very frequently as the camera moves(The map might be several kilometers long). So I'll have to do that again and again, and it will affect the game experience.(Because doing your action will send the sprites should be in the back to the front at first).
But I think replacing “remove the sprites came out and create the sprites going in” to “move the sprites came out to the position of going in” might help with this problem, because there isn't new instances need to be created.
I'll try it out. And what's your opinion about this idea?

Last edited by zbx1425 (Oct. 5, 2017 12:09:09)

gtoal
Scratcher
1000+ posts

How to layout sprites in a specific depth order?

You should be able to create the sprites in order and then just never change the order. It is much cleaner than trying to manage it by using the push back n layers block.
cixi-pixy23
Scratcher
1 post

How to layout sprites in a specific depth order?

Finnthebest12 wrote:

well you could write a script that, starting at the sprite that should be at the back, sets it to the front when the game is started, then broadcasts a message to the second last sprite(in terms of which sprite should be near the front) then that brings that sprite to the front and broadcasts a message to the next sprite, etc. like the scripts i used to layer some of the sprites ( the car and the roads) in this project: https://scratch.mit.edu/projects/177413383/




that is very helpful,thank you
donotforgetmycode
Scratcher
1000+ posts

How to layout sprites in a specific depth order?

cixi-pixy23 wrote:

that is very helpful,thank you
Please don't necropost.
(Necroposting is when you make an unconstructive post on an old thread.)
Harakou
Scratcher
1000+ posts

How to layout sprites in a specific depth order?

cixi-pixy23 wrote:

that is very helpful,thank you
It's great that this helped you, but it's also a very old topic. Please avoid bumping old threads that don't require assistance any more - this is known as “necroposting.” When you do this, it bumps the topic back to the top of the page and creates a lot of confusion. Thanks!

Last edited by Harakou (March 6, 2022 20:47:47)

Powered by DjangoBB