This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-12-13 21:07:46

superhero111
Scratcher
Registered: 2008-06-02
Posts: 13

Scrolling Sprites

How do I make a sprite scroll?
My background is one big sprite and I make it move to make my game scroll.
How do I make a sprite move with the background?
I have the variables Wherex and Wherey to mark where the main character "is".
Also, how do I make a sprite move in addition to it scrolling with the background?
Thanks so much!


Great Game: Platformer-Earn more superpowers as you explore and advance rooms in the cave.
Play the Game: Superpower Cave

Offline

 

#2 2010-12-13 22:51:27

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Scrolling Sprites

Try using this script:
http://www.freeimagehosting.net/uploads/839ccff872.gif
This will make the sprite always move with the background.

For the second question, rather than using the "change x by" script, use these:
http://www.freeimagehosting.net/uploads/47d0e6a812.gif
Again, replace 1 and -1 with however much you want the character to move.

Assuming you're only scrolling by the X axis, you won't need the Wherey variable at all. Does that make sense?


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#3 2010-12-14 19:20:57

superhero111
Scratcher
Registered: 2008-06-02
Posts: 13

Re: Scrolling Sprites

Thank you for providing me with that code, though I'm asking about a non-main character like a box that you encounter as you work your way through the level or a guard. How do you do that?
P.S. Also, I'm going to have my game scroll both in the x direction and in the y direction.
P.S.S. I'm using When you press Right Arrow etc. so I can have an animation for walking.


Great Game: Platformer-Earn more superpowers as you explore and advance rooms in the cave.
Play the Game: Superpower Cave

Offline

 

#4 2010-12-14 20:43:39

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Scrolling Sprites

Sorry, I completely forgot there's a much better way of doing that script! Disregard that other post - my mistake  sad

http://www.freeimagehosting.net/uploads/06c2239460.gif

You'll need to replace the "10"s with the Scrollx and Scrolly where the sprite should be in the center of the screen. The best way to find that is to move until you find the spot where the sprite should appear, then replace the "10"s with the current Scrollx and Scrolly values. Then, adjust the numbers until it's in the right place!

Is that what you're looking for?


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#5 2010-12-16 21:35:17

superhero111
Scratcher
Registered: 2008-06-02
Posts: 13

Re: Scrolling Sprites

What do you mean by scrollx and scrolly?
So far, I am changing wherex and wherey this way:
Whenever someone presses the right arrow,
[blocks] <change{wherex}by(10 [/blocks]
and the background moves to the left for 10 steps.


Great Game: Platformer-Earn more superpowers as you explore and advance rooms in the cave.
Play the Game: Superpower Cave

Offline

 

#6 2010-12-17 17:28:15

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Scrolling Sprites

Scrollx and Scrolly are used kind of like how (I think) you're using Wherex and Wherey - they're used to mark the camera's position. Rather than using the move 10 steps block to move the background, you'd change Scrollx and Scrolly and make the background sprite(s) set their X and Y accordingly (see this project for an example). I just assumed you were using those, sorry. But if that works, you can still use that same script, just with the http://wiki.scratch.mit.edu/images/%28%29_of_%28%29_%28Sensing%29.png block to detect the X and Y positions of the background sprite, and put those in place of the Scrollx and Scrolly blocks.

I'd imagine that would work - it's kind of hard without knowing exactly what you're using to scroll.


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#7 2010-12-18 13:48:56

superhero111
Scratcher
Registered: 2008-06-02
Posts: 13

Re: Scrolling Sprites

Thank you for providing me with that code, though I'm asking about a non-main character like a box that you encounter as you work your way through the level or a guard-Not the character you're controlling throughout the game. How do you do that?
Please look at this picture:
http://scratch.mit.edu/projects/superhero111/1487866
I want to make something like the box in that picture scroll _with_ the background, but since I want to make it interactive, I want to make it it's own separate sprite.
How do you do that with _both_ X and Y scrolling _together_?


Great Game: Platformer-Earn more superpowers as you explore and advance rooms in the cave.
Play the Game: Superpower Cave

Offline

 

#8 2010-12-18 15:24:02

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Scrolling Sprites

That's what that script is supposed to do, but you were just using a different method of scrolling than that works for. Here - I've uploaded a project that should work for you: http://scratch.mit.edu/projects/hmnwilson/1488033


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#9 2010-12-18 21:06:32

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Scrolling Sprites

http://scratch.mit.edu/projects/archmage/635312

For a 2 way platformer scrolling project this project has the best code to learn off of. It has what you are describing, both stationary and moving objects in the scrolling area. I really recommend you get a feel for how this project was created and learn how to remake it from nothing by yourself.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#10 2010-12-23 20:52:56

superhero111
Scratcher
Registered: 2008-06-02
Posts: 13

Re: Scrolling Sprites

Both of you, thanks for the help. The scrolling really works-Thanks so much!

Last edited by superhero111 (2010-12-24 09:59:56)


Great Game: Platformer-Earn more superpowers as you explore and advance rooms in the cave.
Play the Game: Superpower Cave

Offline

 

Board footer