Discuss Scratch

royalguard006
Scratcher
29 posts

How do I make a scrolling background?

For my game photon-shot I have decided to make a scrolling background because the game is starting to feel cramped how would I go about this?
The game:https://scratch.mit.edu/projects/880660062
NMario84
Scratcher
1000+ posts

How do I make a scrolling background?

https://en.scratch-wiki.info/wiki/Scrolling_(sprites)

Since you can't change the X Y of the background itself, you make the background a sprite object.
Basically, set X position of background sprite to Variable + (480 * 0). Then add or subtract the variable depending which way you want it to move.
DylTLip
Scratcher
35 posts

How do I make a scrolling background?

NMario84 wrote:

https://en.scratch-wiki.info/wiki/Scrolling_(sprites)

Since you can't change the X Y of the background itself, you make the background a sprite object.
Basically, set X position of background sprite to Variable + (480 * 0). Then add or subtract the variable depending which way you want it to move.

setxtospeed+480*0

So using something like this above? if so, why do you do 480 * 0? That would just = 0; are you supposed to change this value to something?
NMario84
Scratcher
1000+ posts

How do I make a scrolling background?

480 is the width of the canvas. So each new background you want to scroll would be 480*1, 480*2, 480*3, 480 *4, etc.

480*0 would indeed output 0, therefore the background would remain at 0,0, which is your starting point. 480*1 would output 480. Since it is positive value, it would be placed 480 pixels to the right of the canvas until you change the value of your variable to make it scroll the other way.

If you want to scroll it upwards/downwards, you would want to use 360 for Y position in place of 480. The Scratch screen window is 480x360.

Last edited by NMario84 (Aug. 30, 2023 20:40:12)

DylTLip
Scratcher
35 posts

How do I make a scrolling background?

NMario84 wrote:

480 is the width of the canvas. So each new background you want to scroll would be 480*1, 480*2, 480*3, 480 *4, etc.

480*0 would indeed output 0, therefore the background would remain at 0,0, which is your starting point. 480*1 would output 480. Since it is positive value, it would be placed 480 pixels to the right of the canvas until you change the value of your variable to make it scroll the other way.

If you want to scroll it upwards/downwards, you would want to use 360 for Y position in place of 480. The Scratch screen window is 480x360.

Ohhhh so this is using clones to create the background? I have never seen this method for creating a scrolling background before. I might borrow that.
NMario84
Scratcher
1000+ posts

How do I make a scrolling background?

Yea. This is assuming we're using clones here.

You could “probably” do it with vector images without too much cloning, but I imagine it would be a lot harder. If the vector image exceeds the field of view somehow, you would then have to get the size of that vector image, use that value if you need to scroll another vector image against the original.

Though I try not to use vector images in my own projects anyway. It's just a preference of presentation, I guess. Maybe vector images are better depending what kind of project you want to make, though you would have to consider the loading times, and the size of the images for that case.
DylTLip
Scratcher
35 posts

How do I make a scrolling background?

NMario84 wrote:

Yea. This is assuming we're using clones here.

You could “probably” do it with vector images without too much cloning, but I imagine it would be a lot harder. If the vector image exceeds the field of view somehow, you would then have to get the size of that vector image, use that value if you need to scroll another vector image against the original.

Though I try not to use vector images in my own projects anyway. It's just a preference of presentation, I guess. Maybe vector images are better depending what kind of project you want to make, though you would have to consider the loading times, and the size of the images for that case.
I shall take this into consideration in future projects. Looks like I learned something from this post too!
EnchantingRoserade
Scratcher
100+ posts

How do I make a scrolling background?

Try this for backdrops. (its object lol)


gotox:scrollXy:Whaterveryourbackdropyis/scratchblocks/}

Powered by DjangoBB