Discuss Scratch

TheLegendaryFox12
Scratcher
2 posts

How to swap a specific backdrop depending on the edge you are touching

So im working on a game and i was wondering how to make it so that if you are touching one side it swaps to a background and if you touch the oppisite side it swaps to a different backdrop please i need it fast cuz it is for a school project
mstone326
Scratcher
1000+ posts

How to swap a specific backdrop depending on the edge you are touching

You can measure your position on the x axis. Maybe if your x position > 220, then switch to the next backdrop to the right (don't forget to position your sprite to the left). If you x position < -220, switch to the previous back drop (don't forget to set your sprite to the right).
theredviking
Scratcher
100+ posts

How to swap a specific backdrop depending on the edge you are touching

mstone326 wrote:

You can measure your position on the x axis. Maybe if your x position > 220, then switch to the next backdrop to the right (don't forget to position your sprite to the left). If you x position < -220, switch to the previous back drop (don't forget to set your sprite to the right).

That's pretty much it, but there are easier ways. Create a sprite named Edge1, and give it a color. The sprite should basically be a long thin line. let's suppose that I colored the long thin line green. Then put this script in your playable character:


when green flag clicked
if <touching color [#13ec03] ?> then
switch backdrop to [Level2]
end


There's an even simpler way. The long thin line doesn't need to be assigned a color. Here's the script you have to put in your playable character for this:

when green flag clicked
if <touching [Line1] ?> then
switch backdrop to [Level2]
end
theredviking
Scratcher
100+ posts

How to swap a specific backdrop depending on the edge you are touching

Sorry, instead of putting in switch costume to Level2, just enter switch to next backdrop.
mstone326
Scratcher
1000+ posts

How to swap a specific backdrop depending on the edge you are touching

theredviking wrote:

mstone326 wrote:

You can measure your position on the x axis. Maybe if your x position > 220, then switch to the next backdrop to the right (don't forget to position your sprite to the left). If you x position < -220, switch to the previous back drop (don't forget to set your sprite to the right).

That's pretty much it, but there are easier ways. Create a sprite named Edge1, and give it a color. The sprite should basically be a long thin line. let's suppose that I colored the long thin line green. Then put this script in your playable character:


when green flag clicked
if <touching color [#13ec03] ?> then
switch backdrop to [Level2]
end


There's an even simpler way. The long thin line doesn't need to be assigned a color. Here's the script you have to put in your playable character for this:

when green flag clicked
if <touching [Line1] ?> then
switch backdrop to [Level2]
end

That would work but using color detection in Scratch is the slowest form. I believe, don't quote me, that it is position, then touching sprite, then touching color for the fastest to slowest for checking conditions.

If you wanted to use the touching green option, best to make a green sprite as a thin line, call it green, then use a script if touching sprite green.

Best to avoid color detection at all costs if possible.
TheLegendaryFox12
Scratcher
2 posts

How to swap a specific backdrop depending on the edge you are touching

mstone326 wrote:

You can measure your position on the x axis. Maybe if your x position > 220, then switch to the next backdrop to the right (don't forget to position your sprite to the left). If you x position < -220, switch to the previous back drop (don't forget to set your sprite to the right).
This worked really well but with some slight modifications. when i did it before it would have a spasm and switch 100 backdrops at once so i just modified it to swap positions and other things. thanks so much for the help though
lia_stories246
Scratcher
7 posts

How to swap a specific backdrop depending on the edge you are touching

TheLegendaryFox12 wrote:

mstone326 wrote:

You can measure your position on the x axis. Maybe if your x position > 220, then switch to the next backdrop to the right (don't forget to position your sprite to the left). If you x position < -220, switch to the previous back drop (don't forget to set your sprite to the right).
This worked really well but with some slight modifications. when i did it before it would have a spasm and switch 100 backdrops at once so i just modified it to swap positions and other things. thanks so much for the help though
i tired this it worked for the first time but it just keeps oing to that can you let me know what modifications you made ?:
legendary34678
Scratcher
1000+ posts

How to swap a specific backdrop depending on the edge you are touching

Hello, please don't necropost on old topics. Thanks!
09HIY3
New Scratcher
1 post

How to swap a specific backdrop depending on the edge you are touching

IT DIDNT WORK

Powered by DjangoBB