Discuss Scratch

DeltaDinosaur
Scratcher
8 posts

How can I make an infinite scrolling background?

Hey people,

Im a relatively new scratcher, so please don't tear down my work! Today, I started work on a space shooter, and I wanted to make a scrolling backdrop, but I ran into a bug. Its fine for the first few seconds, but after that, there's always a HUGE gap flashing every now and then between the backdrop and its clone. Check out my code, hopefully you can tell me i did something wrong, and a possible way I can fix it!


when flag clicked
go to x: [0] y: [0]
create clone of [myself]
set [LIGHTSPEED] to [4]
forever
if <(x position) > (-465)>then
change x by ((LIGHTSPEED)*(-1))
else
go to x: [0] y: [0]
end
end

the second block of code is here:

when I start as a clone
go to x: [0] y:[0] 


forever
if <(x position) > (35)>then
change x by ((LIGHTSPEED)*(-1))
else
go to x: [350] y: [0]
end
end


Thanks,
Delta Dinosaur

Last edited by DeltaDinosaur (June 6, 2020 01:21:30)

AidyGamer60
Scratcher
100+ posts

How can I make an infinite scrolling background?

Try not using a clone, and make the background scroll continuously. I’ll show the new script here:

when green flag clicked
forever
if <(x position) = [position right before white appears]> then
go to x: [starting position] y: [your choice]
else
move [speed and direction] steps
wait [optional] secs
end
DeltaDinosaur
Scratcher
8 posts

How can I make an infinite scrolling background?

Thanks, I'll give it a try!
DeltaDinosaur
Scratcher
8 posts

How can I make an infinite scrolling background?

AidyGamer60 wrote:

Try not using a clone, and make the background scroll continuously. I’ll show the new script here:

when green flag clicked
forever
if <(x position) = [position right before white appears]> then
go to x: [starting position] y: [your choice]
else
move [speed and direction] steps
wait [optional] secs
end

Thanks a lot for your response, but I still have a big white gap when its moving.

Any other ideas?
DeltaDinosaur
Scratcher
8 posts

How can I make an infinite scrolling background?

Hey people,

I have found a soloution, but I ran into another bug. There's a skip during the time it moves back. It kinda skips forward, but there isnt a gap. Do you think I should find another method? Here's my code:


when flag clicked
go to x: [-15] y: [0]
create clone of [myself]
set [LIGHTSPEED] to [4]
forever
if <(x position) > (-465)>then
change x by ((LIGHTSPEED)*(-1))
else
go to x: [-15] y: [0]
end
end

the second block of code is here:

when I start as a clone
go to x: [465] y:[0]
forever
if <(x position) > (15)>then
change x by ((LIGHTSPEED)*(-1))
else
go to x: [465] y: [0]
end
end


Thanks,
Delta Dinosaur

Last edited by DeltaDinosaur (June 6, 2020 03:41:14)

AidyGamer60
Scratcher
100+ posts

How can I make an infinite scrolling background?

That isn’t a bug The background might be uneven. Try making a pattern on the background! That might help it.
DeltaDinosaur
Scratcher
8 posts

How can I make an infinite scrolling background?

Hey people, here is what I was working on, so check out the code for yourself:

https://scratch.mit.edu/projects/402519204/

Last edited by DeltaDinosaur (June 7, 2020 00:02:13)

DeltaDinosaur
Scratcher
8 posts

How can I make an infinite scrolling background?

Hey people,

I've found a fix by adjusting the code even more, and adding a backdrop to cover the bugs. Check out my game on the link on the post above, so you can see my coding and stuff.

Thanks,
DeltaDinosaur
beard-cat
Scratcher
47 posts

How can I make an infinite scrolling background?

All you need to do to create a. scaling background is to mesh multiple sprites together, as they move across the screen
HannibalZak
Scratcher
7 posts

How can I make an infinite scrolling background?

Maybe make humongous Sprite acting lick a background, and do this?:

Code for character:
when green flag clicked
go to x: (0) y: (0)
forever
if <key [right arrow] pressed?> then
change [backgroundx] by (10)
end
end

Code for sprite acting as background:
when green flag clicked
forever
set x to (backgroundx)
end


And just repeat all that code for every single arrow key. Also, you need to create a new variable called backgroundy, and use that for the up and down arrows.
Right arrow: Change backgroundx by 1.
Left arrow: Change backgroundx by -1
Up arrow: Change backgroundy by 1
Down arrow: Change backgroundy by -1

I haven't tested this method, and it might work… I dunno. Also this background doesn't last forever. Sorry if I'm necroposting. Maybe this will help the owner of this topic I dunno.

Last edited by HannibalZak (Jan. 6, 2021 00:11:47)

--cherrykitty--
Scratcher
500+ posts

How can I make an infinite scrolling background?

You can use frames instead, like you can have many backdrops that infinitely loop, and in each backdrop, the elements move forward a little, and after they run out of the screen, then let it go back to the top of the screen at the same position. If you don't quite get what I mean, you can have a look at my 1s1s1c platformer, it uses this method to do the snowing effect.
toom342
Scratcher
1 post

How can I make an infinite scrolling background?

please help me
HannibalZak
Scratcher
7 posts

How can I make an infinite scrolling background?

Make a variable called XPos. Then create two sprites that are acting as a backdrop, that are identical, then do this:

Code for 1st sprite acting as a backdrop:

when green flag clicked
forever
set x to (XPos)
end

Code for 2nd sprite acting as a backdrop:

when green flag clicked
forever
set x to ((XPos) + (480))
end

Now make a player or empty sprite, and do this.

Code if you have player:

when green flag clicked
set rotation style [left-right]
set [XPos] to [0]

when [right arrow] key pressed
point in direction (90)
change [XPos] by (-5)

when [left arrow] key pressed
point in direction (-90)
change [XPos] by (5)

Code if you have empty sprite:

when green flag clicked
set [XPos] to [0]

when [right arrow] key pressed
change [XPos] by (-5)

when [left arrow] key pressed
change [XPos] by (5)

That's it! I haven't tested it though.
If this doesn't work try this: https://coderdojoathenry.org/2016/03/01/beginners-scratch-challenge-12-scrolling-backgrounds/
Kisaan10
Scratcher
2 posts

How can I make an infinite scrolling background?

I want to Code a scrolling backround on a backdrop not a sprite pls help
AksharPremnath
Scratcher
500+ posts

How can I make an infinite scrolling background?

Kisaan10 wrote:

I want to Code a scrolling backround on a backdrop not a sprite pls help

Please make your own topic. As far as I know, there is no way to use a backdrop as a scrolling background. The only way theoretically to do this would be to have multiple stage costumes for each x position you can scroll so there would be 480 costumes minimum.
bunnyCoder16
Scratcher
500+ posts

How can I make an infinite scrolling background?

DeltaDinosaur wrote:

Hey people,

Im a relatively new scratcher, so please don't tear down my work! Today, I started work on a space shooter, and I wanted to make a scrolling backdrop, but I ran into a bug. Its fine for the first few seconds, but after that, there's always a HUGE gap flashing every now and then between the backdrop and its clone. Check out my code, hopefully you can tell me i did something wrong, and a possible way I can fix it!


when flag clicked
go to x: [0] y: [0]
create clone of [myself]
set [LIGHTSPEED] to [4]
forever
if <(x position) > (-465)>then
change x by ((LIGHTSPEED)*(-1))
else
go to x: [0] y: [0]
end
end

the second block of code is here:

when I start as a clone
go to x: [0] y:[0] 


forever
if <(x position) > (35)>then
change x by ((LIGHTSPEED)*(-1))
else
go to x: [350] y: [0]
end
end


Thanks,
Delta Dinosaur

Try using this video by the scratch team:.
Here is the link: https://youtu.be/CvSOVWyyjJI

Powered by DjangoBB