I need Help making a Scrolling Background when i use arrow keys

id: 560240

category: Help with Scripts

posts: 5

I need Help making a Scrolling Background when i use arrow keys, im making a shooter game
https://scratch.mit.edu/projects/605245577/editor
1. Create a separate sprite with the background images- be warned that images above 960x720 may become blurry.
2. Use the resize exploit to make the background larger than 150%.
3. Invert the arrow key controls for backgrounds; press right to move left, left to move right, etc.
I can't seem to be able to view the project but I'll try and help.

Make a spite simply for the background, two costumes; a small dot and the background you want (the size of the border)

switch costume to [small dot v]
set size to (999) %
switch costume to [background v]
This'll allow for a much larger size of the background that you may need.

forever
if <key [right arrow v] pressed?> then
change x by (2)
end
if <key [left arrow v] pressed?> then
change x by (-2)
end
end

Depending on what you want it to look like, this may or may not work. The values may need to be changed as well.
Arctevious Arctevious loading
I've had this problem too (but once I figured it out it was just better to change the scene one by one) but anyway.

first, make a sprite and call it “player”, next make your background (color and position whatever you want)
then click the entire thing and copy it (ctrl+X or right-click copy or press the scratch button copy)
then what you need to do is make the background into a sprite. to do this just click new sprite and paste the image in and adjust.
next, we need the background sprite to react to the player touching it. the key is the player doesn't move an inch…
only the background moves! invert the controls and change player costumes to give the illusion that your character is moving and not the stage.

(background sprite only) to make the stage move, write code like this;

when green flag clicked
set [speed v] to [1.5]

when green flag clicked
forever
if <key [right v] pressed?> then
broadcast [ moving right v]
change x by ((-1) * (speed))
end
end

when green flag clicked
forever
if <key [left v] pressed?> then
broadcast [ moving left v]
change x by (speed)
end
end

when green flag clicked
forever
if <key [up v] pressed?> then
broadcast [ moving up v]
change y by ((-1) * (speed))
end
end

when green flag clicked
forever
if <not <<key [left v] pressed?> and <<key [up v] pressed?> and <key [right v] pressed?>>>> then
broadcast [not moving v]
end
end

this tells the background to move in a certain direction when a key is pressed along with some broadcasts to tell the player sprite to change costumes when you are moving. you may notice that the background movements are inverted to the controls, this is to make the player sprite look as if they are moving.

(player sprite only) put whatever sprite costumes you draw in the blank spaces below;

when I receive [moving right v]

when I receive [moving left v]

when I receive [moving up v]

when I receive [not moving v]

(background sprite only) now for the walls and how the sprite doesn't see them and just passes them. let's fix this;

first, let's make this sprite HUGE!!!

when green flag clicked
set size to (999) %
go to x: (0) y: (0)

when green flag clicked
forever
if <<touching [player v] ?> and <key [right v] pressed?>> then
change x by (0.1)
end
end

repeat this process with all the other movements like up and left
and voila! a scrolling background!

you may have noticed the player doesn't fall… yea… that's up to you really, depends on when you want your player to do, so I can't help you there except for saying;

when green flag clicked
forever
if <not <touching [player v] ?>> then
change y by (1)
end
end

(this isn't tested so if it doesn't work ill fix it)
hope this works for you!
when green flag clicked
forever
if <> then
<key [ a] pressed?>
change x by (-10)
if <> then
<key [ d] pressed?>
change x by (10)