Discuss Scratch

icode3662
Scratcher
14 posts

Help with Layering

I am currently working on a project that uses multiple layers to function. There are sets of backgrounds in between the layers, but I cannot get them to layer properly with the clones being spawned on their given layer.

I tried to make a simple script that counts how many soldiers are on a given layer and sends them backwards that many times, but it seems to be completely broken…

If anyone wants to check out the code and help me, the development key is “LUNA”
The Game
deck26
Scratcher
1000+ posts

Help with Layering

If you think you can have multiple soldiers on the same layer I'm afraid you're mistaken. The number of layers is the same as the number of objects (sprites and clones) with each object on a separate layer.

You may need to rethink how you're managing lyering.
souleymane2
Scratcher
100+ posts

Help with Layering

Hey there,

as deck previously said, you cannot have multiple sprites or objects on the same layer. The best way to vizualize it all is with a list.

Assuming you have ground 1 as the first item and ground 2 as the second item of the list.

If you add a soldier in between ground 1 and ground 2, you can make them move backwards by 1 layer.

But then if you want to layer somethign behind ground 2, you need to move backwards by 3 slayers to place it behind it. This problem gets amplified as you add more and more clons to the project.

So how would I fix this? Well i would use list.

If you give each clone a separate clone ID, and then add those ID's to a list, you can edit the layer of each clone and the ground depending on the position of the clone id of the list.

gotofrontgobackitem#ofCloneIDinlayers-1layers

something like this should work.
icode3662
Scratcher
14 posts

Help with Layering

Assuming you have ground 1 as the first item and ground 2 as the second item of the list.

If you add a soldier in between ground 1 and ground 2, you can make them move backwards by 1 layer.

But then if you want to layer somethign behind ground 2, you need to move backwards by 3 slayers to place it behind it. This problem gets amplified as you add more and more clons to the project.

So how would I fix this? Well i would use list.

If you give each clone a separate clone ID, and then add those ID's to a list, you can edit the layer of each clone and the ground depending on the position of the clone id of the list.

Thank you so much! I will try it out and see how it works out.

Also, I do know that multiple sprites cant be on the same layer. That is why I am having issues in the first place.
icode3662
Scratcher
14 posts

Help with Layering

So, I counted how many times you need to go backwards to get to a given layer, and added that to the amount of soldiers.

gotofrontgobackAmountofSoldierClones+LayerNumberlayers

Unfortunately, that did not work. After a few spawns the clones just started going infront of of the trees or behind the ground. I am really not sure what is causing this.

Maybe I should remove that concept entirely?

Last edited by icode3662 (Aug. 28, 2024 18:59:35)

icode3662
Scratcher
14 posts

Help with Layering

UPDATE: I found a code that works. Basically, I count how many sprites there are on any given layer and go backwards by that amount + a little extra at the end so it works.

ifLayer=1thengotofrontgobackAmountittakestogettolayerlayerschangeSprites on Layer 1by1

ifLayer=2thengotofrontgobackSpritesonlayer1+Amountittakestogettolayer)layerschangeSprites on Layer 2by1

ifLayer=3thengotofrontgobackSpritesonlayer1+SpritesonLayer2+Amountittakestogettolayer)layerschangeSprites on Layer 3by1

And so on.

The only limitation her is that you have to increase the “Amount it takes to get to layer” every time you add a new sprite, but overall it works pretty great and there is minimal bugs.
souleymane2
Scratcher
100+ posts

Help with Layering

Perfect!

Powered by DjangoBB