Discuss Scratch

cheesycasper
Scratcher
15 posts

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

I need Help making a Scrolling Background when i use arrow keys, im making a shooter game
https://scratch.mit.edu/projects/605245577/editor
bluedragon8633
Scratcher
1000+ posts

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

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.
arcader_games
Scratcher
25 posts

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

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)

switchcostumetosmall dotsetsizeto999%switchcostumetobackground
This'll allow for a much larger size of the background that you may need.

foreverifkeyright arrowpressed?thenchangexby2ifkeyleft arrowpressed?thenchangexby-2

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
Scratcher
500+ posts

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

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;

whenclickedsetspeedto1.5

whenclickedforeverifkeyrightpressed?thenbroadcast moving rightchangexby-1*speed

whenclickedforeverifkeyleftpressed?thenbroadcast moving leftchangexbyspeed

whenclickedforeverifkeyuppressed?thenbroadcast moving upchangeyby-1*speed

whenclickedforeverifnotkeyleftpressed?andkeyuppressed?andkeyrightpressed?thenbroadcastnot moving

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;

whenIreceivemoving right

whenIreceivemoving left

whenIreceivemoving up

whenIreceivenot moving

(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!!!

whenclickedsetsizeto999%gotox:0y:0

whenclickedforeveriftouchingplayer?andkeyrightpressed?thenchangexby0.1

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;

whenclickedforeverifnottouchingplayer?thenchangeyby1

(this isn't tested so if it doesn't work ill fix it)
hope this works for you!

Last edited by Arctevious (Nov. 22, 2021 22:10:28)

Rayquaza2015
Scratcher
3 posts

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

whenclickedforeverifthenkey apressed?changexby-10ifthenkey dpressed?changexby10

Last edited by Rayquaza2015 (March 27, 2024 21:23:38)

HungryBunny28
Scratcher
1 post

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

this is hard

Powered by DjangoBB