Discuss Scratch

XxStarCatxX
Scratcher
80 posts

making the sprite move with the background

Okay, so here's what i'm having trouble with… I was thinking how do you make the sprite move with the background? Like, with the arrow keys, the person moves the sprite. When they get to the end of the background, the background moves forward with the sprite. Anyone get it? Sorry, its just its with meh game…

Come see my Animal Jam forum here!
Also, check out my art and projects, you won't regret it!
bjskistad
Scratcher
1000+ posts

making the sprite move with the background

You need to learn about Scrolling, which you can find here: http://wiki.scratch.mit.edu/wiki/Scrolling_(sprites) .

Kumquat was Here
AwesomeSmilee
Scratcher
500+ posts

making the sprite move with the background

Scrolling? …Make a sprite which has all of your backdrops, like costume 1 has a village, costume 2 has mountains etc. then do this:
when gf clicked
set [scrollX v] to (-240)
set [scrollY v] to (what Y position the ground is)
show
switch costume to [first costume v]
set [id (only for this sprite) v] to (0)
repeat (number of costumes)
change [id v] by (1)
create clone of [myself v]
end
hide
when I start as a clone
forever
go to x: ((scrollX) + ((id) * (240))) y: (scrollY)
// Meanwhile, in the player sprite...
... :: hat
...
forever
if <key [key for moving right v] pressed?> then
if <(x position) < [0]> then
change x by (how much you want to move)
else
change [scrollX v] by (how much you want to move)
end
end
if <key [key for moving left v] pressed?> then
if <(x position) > [0]> then
change x by (how much you want to move left)
else
change [scrollX v] by (how much you want to move left)
If you want jumping, there's a bit more to it. But this should cover what you're asking for.
EDIT: ninja'd obviously…

Last edited by AwesomeSmilee (Dec. 24, 2015 16:11:17)

999narutoleaf
Scratcher
7 posts

making the sprite move with the background

that is a long one but I will try
deck26
Scratcher
1000+ posts

making the sprite move with the background

See if this helps https://scratch.mit.edu/projects/92682141/

However, like most scrollers it assumes the player stays central and the background moves. You can tweak it so that you only change scrollx when the player is at an edge - eg only scroll if changing x would make it less than -200 or more than 200 and don't change x if that is the case.
RholanT3344
Scratcher
62 posts

making the sprite move with the background

(my way so it might not work.)
Make a sprite.
example: this
then use this script: (on the bg sprite)
when green flag clicked
go to x: (0) y: (0)
forever
if <key [left arrow v] pressed?> then
create clone of [myself v]
move (join [-] (speed)) steps
end
if <key [right arrow v] pressed?> then
create clone of [myself v]
move (join [] (speed)) steps
end
end
(the join things are for speed, if you want to do this, type a number.)
if the link doesn't work try this:
file:///C:/Users/rhola/AppData/Local/Temp/7zO8C187AFF/4.svg

Last edited by RholanT3344 (Oct. 7, 2017 01:02:02)


when green flag clicked
broadcast [test v]

when I receive [test v]
if <following [RholanT3344]::sensing> then
say [ok]

else
say [ok, you can do it later]
end
broadcast [test v]
deck26
Scratcher
1000+ posts

making the sprite move with the background

RholanT3344 wrote:

(my way so it might not work.)
Make a sprite.
example: this
then use this script: (on the bg sprite)
when green flag clicked
go to x: (0) y: (0)
forever
if <key [left arrow v] pressed?> then
create clone of [myself v]
move (join [-] (speed)) steps
end
if <key [right arrow v] pressed?> then
create clone of [myself v]
move (join [] (speed)) steps
end
end
(the join things are for speed, if you want to do this, type a number.)
if the link doesn't work try this:
file:///C:/Users/rhola/AppData/Local/Temp/7zO8C187AFF/4.svg
You give no indication of what the clones are doing or why you create them. Better, in my view, to multiply by -1 than join ‘-’ to a variable. What if join is already negative and you've done this multiple times, for example. Move ————————-5 steps??
kewi_lover
Scratcher
1 post

making the sprite move with the background

deck26
Scratcher
1000+ posts

making the sprite move with the background

kewi_lover wrote:

Please don't necropost.
mrkrab15
New to Scratch
1 post

making the sprite move with the background

thank you mame im so so so hippy thankkkkkk kyoyouyouooyyoyot for it
crazy2infinity
Scratcher
2 posts

making the sprite move with the background

It works thanks

Last edited by crazy2infinity (April 26, 2020 04:52:19)

TheGnarly
New to Scratch
1 post

making the sprite move with the background

it didn't work for me but thank you

Last edited by TheGnarly (Sept. 1, 2020 13:33:15)

deck26
Scratcher
1000+ posts

making the sprite move with the background

TheGnarly wrote:

it didn't work for me but thank you
There's no need to necropost to comment whether or not it worked or to thank anyone. All it does is move someone currently needing help off the top page of the forum.
dccricket
Scratcher
1 post

making the sprite move with the background

Will it work for running or racing games?

Powered by DjangoBB