Discuss Scratch

Fox-raven
Scratcher
92 posts

Scrolling Background

I started making this game. It has a scrolling background. To move your avatar, you hold the mouse in front of the avatar and the background scrolls in the direction of your mouse. When you release the mouse, it stops. Also, there is a simple walking animation to go along with it-when the character is not moving it switches to the idle costume. That's what I've done so far. I would like to know how I might prevent the background sprite from going off the screen, and maybe how to figure out jumping?
powercon5
Scratcher
1000+ posts

Scrolling Background

Could you share and link the project so we can see the scripts you are using?

So you want to create a barrier that the player can not move through?
Uniquename1
Scratcher
100+ posts

Scrolling Background

Depending what you have for the scroll variable and what exactly you mean. You do something like

when green flag clicked
forever
if <<key [ right arrow] pressed?> and <(scrollx) > [-10000]>> then
change [ (scrollx)] by (5)
end
end

Your scrollx likely goes between 0 and negative 10000 or something so when left arrow pressed and scrolll x is less than zero and when right arrow pressed and scrollx is more than -10000 or whatever numbers you need. You can turn on and watch what scroll x is/ does as you move by checking the box in variables see what your min and max values are in the space you'd like to be.

Last edited by Uniquename1 (July 6, 2017 22:17:29)

Fox-raven
Scratcher
92 posts

Scrolling Background

Uniquename1 wrote:

Depending what you have for the scroll variable and what exactly you mean. You do something like

when green flag clicked
forever
if <<key [ right arrow] pressed?> and <(scrollx) > [-10000]>> then
change [ (scrollx)] by (5)
end
end

Your scrollx likely goes between 0 and negative 10000 or something so when left arrow pressed and scrolll x is less than zero and when right arrow pressed and scrollx is more than -10000 or whatever numbers you need. You can turn on and watch what scroll x is/ does as you move by checking the box in variables see what your min and max values are in the space you'd like to be.

Well it's more complicated because I want you to be able to move your avatar by clicking and holding the mouse….but I'll try it

Last edited by Fox-raven (July 6, 2017 23:41:12)

Fox-raven
Scratcher
92 posts

Scrolling Background

Fox-raven wrote:

Uniquename1 wrote:

Depending what you have for the scroll variable and what exactly you mean. You do something like

when green flag clicked
forever
if <<key [ right arrow] pressed?> and <(scrollx) > [-10000]>> then
change [ (scrollx)] by (5)
end
end

Your scrollx likely goes between 0 and negative 10000 or something so when left arrow pressed and scrolll x is less than zero and when right arrow pressed and scrollx is more than -10000 or whatever numbers you need. You can turn on and watch what scroll x is/ does as you move by checking the box in variables see what your min and max values are in the space you'd like to be.

Well it's more complicated because I want you to be able to move your avatar by clicking and holding the mouse….but I'll try it


now my script doesn't work…
Uniquename1
Scratcher
100+ posts

Scrolling Background

Srry implement things you hear on the internet at your own risk. I didn't see you posted a link to your project.

If you're scrolling the background moves off the screen. Thats just what scrolling is. You need another background to slide/ scroll into place to replace the one thats moving. You could clone/ make copies of the background you have and attach each clone to the end of the previous one so it's all one long continuous world. It still moves off screen and the one next to it would be the place next to it that comes on screen as the last one goes off screen so there are no gaps in your world. I'll let you figure out the actual code especially since however it is you're doing the scrolling is unlike anything I've ever seen.

You should look at some of the tutorials for scrolling and there are plenty for jumping. While it's not scrolling I think the flying tutorial thats in the editor might shine some light on whats going on or what should be going on.

imagine you're in a tunnel. You look out the side car window and you see the tunnel wall, another tunnel wall and another window full of tunnel wall. Then you come out of the tunnel and there's a tree and some grass. Or better yet a city street. you pass a donut shop, an ice cream shop and a barber. the first screen is your donut shop as you move past it it is now behind you going off screen eventually you don't see it at all it has moved completely off screen, now you're in front of the ice cream shop and you have this whole line of street but you only see part of it at any time. Thats scrolling. If you only want to stay on that one screen with one picture in the background then don't scroll. If you want to move down the whole street then you need more pictures to go in screen at the same time the one before it goes off the screen to create an illusion of motion. You can use the same picture but you'll have to make copies or program it to make copies of itself.
Fox-raven
Scratcher
92 posts

Scrolling Background

Uniquename1 wrote:

Srry implement things you hear on the internet at your own risk. I didn't see you posted a link to your project.

If you're scrolling the background moves off the screen. Thats just what scrolling is. You need another background to slide/ scroll into place to replace the one thats moving. You could clone/ make copies of the background you have and attach each clone to the end of the previous one so it's all one long continuous world. It still moves off screen and the one next to it would be the place next to it that comes on screen as the last one goes off screen so there are no gaps in your world. I'll let you figure out the actual code especially since however it is you're doing the scrolling is unlike anything I've ever seen.

You should look at some of the tutorials for scrolling and there are plenty for jumping. While it's not scrolling I think the flying tutorial thats in the editor might shine some light on whats going on or what should be going on.

imagine you're in a tunnel. You look out the side car window and you see the tunnel wall, another tunnel wall and another window full of tunnel wall. Then you come out of the tunnel and there's a tree and some grass. Or better yet a city street. you pass a donut shop, an ice cream shop and a barber. the first screen is your donut shop as you move past it it is now behind you going off screen eventually you don't see it at all it has moved completely off screen, now you're in front of the ice cream shop and you have this whole line of street but you only see part of it at any time. Thats scrolling. If you only want to stay on that one screen with one picture in the background then don't scroll. If you want to move down the whole street then you need more pictures to go in screen at the same time the one before it goes off the screen to create an illusion of motion. You can use the same picture but you'll have to make copies or program it to make copies of itself.

So then…I can't just make a button that makes you go into another area then?

Last edited by Fox-raven (July 7, 2017 23:50:27)

HydrixNinja
Scratcher
5 posts

Scrolling Background

First choose a backdrop then go into the costumes and COPY the backdrop and paste it as a SPRITE then use this code(copy the variables!)
when green flag clicked
set [ Xpos1] to [0]
set [ Ypos1] to [0]
go to x: (Xpos1) y: ((Ypos1)
forever
change [ Xpos1] by (-10)
go to x: (Xpos1) y: ((Ypos1)
if <(Xpos1) < [480]> then
set [Xpos1] to [480]
end

Now duplicate the backdrop that you have turned in to a sprite
Once you have done that create a variable called “Xpos2”
now to into the duplicated sprite and all the “Xpos1 and Ypos1” varibles to a“Xpos2”
Look at the second code block of your duplicated backdrop whitch is a sprite
Change the
set [Xpos2] to [0]
into a
set [Xpos2] to [480]

Press the green Flag if there is a small gap in the middle then go to costumes and make it longer
THE END

[scratchblocks]
when green flag clicked
forever
MAKE PEOPLE HAPPY!!!
end

[/scratchblocks]

Last edited by HydrixNinja (June 14, 2020 02:37:31)

HydrixNinja
Scratcher
5 posts

Scrolling Background

in my replie above mine if there are red block INGNORE them!

Last edited by HydrixNinja (June 14, 2020 02:41:49)

rextee33
Scratcher
97 posts

Scrolling Background

HydrixNinja wrote:

First choose a backdrop then go into the costumes and COPY the backdrop and paste it as a SPRITE then use this code(copy the variables!)
when green flag clicked
set [ Xpos1] to [0]
set [ Ypos1] to [0]
go to x: (Xpos1) y: ((Ypos1)
forever
change [ Xpos1] by (-10)
go to x: (Xpos1) y: ((Ypos1)
if <(Xpos1) < [480]> then
set [Xpos1] to [480]
end

Now duplicate the backdrop that you have turned in to a sprite
Once you have done that create a variable called “Xpos2”
now to into the duplicated sprite and all the “Xpos1 and Ypos1” varibles to a“Xpos2”
Look at the second code block of your duplicated backdrop whitch is a sprite
Change the
set [Xpos2] to [0]
into a
set [Xpos2] to [480]

Press the green Flag if there is a small gap in the middle then go to costumes and make it longer
THE END

[scratchblocks]
when green flag clicked
forever
MAKE PEOPLE HAPPY!!!
end

[/scratchblocks]

Sooo, what is the full code 2 copy?
cs2925723
Scratcher
100+ posts

Scrolling Background

Edit: Maybe this?
when green flag clicked
set [ Xpos1 v] to [0]
set [ Ypos1 v] to [0]
go to x: (Xpos1) y: ((Ypos1)
forever
change [ Xpos1 v] by (-10)
go to x: (Xpos1) y: ((Ypos1)
if <(Xpos1) < [480]> then
set [Xpos1 v] to [480]
end

Last edited by cs2925723 (July 29, 2020 16:46:29)

ghastkllr3D
Scratcher
6 posts

Scrolling Background

Fox-raven wrote:

I started making this game. It has a scrolling background. To move your avatar, you hold the mouse in front of the avatar and the background scrolls in the direction of your mouse. When you release the mouse, it stops. Also, there is a simple walking animation to go along with it-when the character is not moving it switches to the idle costume. That's what I've done so far. I would like to know how I might prevent the background sprite from going off the screen, and maybe how to figure out jumping?
Cool

Powered by DjangoBB