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!
Offline
Try using this script:
This will make the sprite always move with the background.
For the second question, rather than using the "change x by" script, use these:
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?
Offline
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.
Offline
Sorry, I completely forgot there's a much better way of doing that script! Disregard that other post - my mistake
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?
Offline
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.
Offline
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 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.
Offline
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_?
Offline
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
Offline
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.
Offline
Both of you, thanks for the help. The scrolling really works-Thanks so much!
Last edited by superhero111 (2010-12-24 09:59:56)
Offline