Discuss Scratch

the_extreme_coder
Scratcher
93 posts

I'm trying to make it so that things that are lower on the Y axis go in front of things that are higher on the Y axis

How would I do this?
deck26
Scratcher
1000+ posts

I'm trying to make it so that things that are lower on the Y axis go in front of things that are higher on the Y axis

Easiest method is to make a broadcast which makes each object wait until a variable is lower than the objects y-position and then it goes to the front. Then run a loop to set the variable to 180 and step it down to -180 - steps of 5 or 10 may be OK rather than stepping 1 at a time. Add a wait 0 seconds and repeat if necessary.

Depends a bit on how much things are changing though. If only one or two objects are changing their layer there will be better ways to do this.
beniwal577
Scratcher
16 posts

I'm trying to make it so that things that are lower on the Y axis go in front of things that are higher on the Y axis

Here maybe try this:
forever
if <(y position) < [0]> then
go back (10) layers
else
go to front
end
end
Put this in each sprite you are using.

Last edited by beniwal577 (Oct. 17, 2021 15:09:47)


when green flag clicked
if <happy> then
have a good day


else
broadcast [become happy v]
end
orangetheory
Scratcher
500+ posts

I'm trying to make it so that things that are lower on the Y axis go in front of things that are higher on the Y axis

We can make 2* global variables, and set them to the y position of the sprite. Then, we can use an if statement to check every single frame whether or not one sprite is higher than the other.
*two is for demonstration purposes. Make as many variables as there are sprites/clones.
Kind of like this:

// in sprite 1
when green flag clicked
forever
set [sprite 1 y pos v] to (y position)
end

// in sprite 2

when green flag clicked
forever
set [sprite 2 y pos v] to (y position)
end

// in sprite 1

when green flag clicked
forever
if <(sprite 1 y pos) > (sprite 2 y pos)> then
go to front
end
end

// in sprite 2

when green flag clicked
forever
if <(sprite 2 y pos) > (sprite 1 y pos)> then
go to front
end
end

Last edited by orangetheory (Oct. 17, 2021 15:11:54)


-Frisbee- -Cricket--Basketball--Forums--Mapping--Coding--Trigonometry master--Mathematics King--Future Prime Minister--Intro-Maker-
I know HTML/CSS, and JavaScript, and with these coding skills I have made some decent projects! Test them out below!
~Archery~Cops + Robbers~
Want an intro, outro, music, effects, or more? Check out the intro shop!

The forum helpers, a place where we help people in the forums
the_extreme_coder
Scratcher
93 posts

I'm trying to make it so that things that are lower on the Y axis go in front of things that are higher on the Y axis

Thank you everyone for the help!

Powered by DjangoBB