Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » making the sprite move with the background
- 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…
- 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:
EDIT: ninja'd obviously…
when gf clickedIf you want jumping, there's a bit more to it. But this should cover what you're asking for.
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)
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.
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)
if the link doesn't work try this:
Make a sprite.
example: this
then use this script: (on the bg sprite)
when green flag clicked(the join things are for speed, if you want to do this, type a number.)
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
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
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?? (my way so it might not work.)
Make a sprite.
example: this
then use this script: (on the bg sprite)when green flag clicked(the join things are for speed, if you want to do this, type a number.)
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
if the link doesn't work try this:file:///C:/Users/rhola/AppData/Local/Temp/7zO8C187AFF/4.svg
- 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
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. it didn't work for me but thank you
- dccricket
- Scratcher
1 post
making the sprite move with the background
Will it work for running or racing games?
- Discussion Forums
- » Help with Scripts
- » making the sprite move with the background