Pages: 1
Topic closed
I want the game to be focused on my main character and to make an effect to make it look like the character is moving positions. Iwant it to be similar to the way it works in super mario and i want the screen to do the same thing when i move backwards as well as when i move forwards. I wouldn't mind a link to a project but i prefer an explanation. Thanks in advance!
Offline
Well - I found a nicely written piece by Jonathanpb, that sums it all up quite nicely... I hope this helps:
Jonathanpb wrote:
Scrolling has one main variable, Scroll X. This variable records where you are on the area.
There are many ways to do scrolling. Here's the compact way, with two sprites for the terrain. The variables:
Scroll X: The usual variable that keeps track of where you are, nothing big.
Terrain number: The variable that tells the terrain sprites what costume to be in.
You need to have several costumes for each terrain sprite; they're going to be the only terrain sprites, so you'll have to re-use them.
There's an easier way to do scrolling, but with many sprites for the terrain. No terrain sprites are re-used - which means that the variable Terrain Number isn't needed.
You'll have noticed one thing we're missing - the script that sets the Scroll X variable! Well, there are two ways: One with velocity, and one without. Here are the two scripts:
And that's it. Some tutorials for scrolling:
archmage's Scrolling Done Right (many-sprite scrolling)
archmage's Efficient Scrolling Demo (two-sprite scrolling) (not exactly a tutorial, but you can download the project and take a look)
Offline
What you are referring to here is a slightly altered version of the classic scrollX system.
It dosen't really belong in advanced topics, more in "all about scratch", but seeing as I can answer, I might as well.
I will explain the scrollX method too, as I assume you don't know about it.
Firstly, you need several sprites lined up to be your background level.
you also need a variable called "scrollX".
scrollX will determine how far along the game you have scrolled.
each background sprite needs the following script:
when green flag clicked: forever: [set y to (0)] [set x to (((scrollx)) +(£) * (%))] end forever
key
£ = Width of background sprites (usually 480)
% = Background sprite number (the further away from the first sprite, the more the calculation is multiplied.
here is that scrollX equation set out as a calculation to make it clearer:
(scrollX + sprite width) * background sprite number
so say that you have two vackground sprites for your game, and scrollX is set to 0
sprite 1 will be set to
(0 + 480) * 1
therefore sprite background 1 is set at 0
sprite 2 will be set to
(0 + 480) * 2
therefore sprite 2 is set at 480.
____________________________________________________________
this way the background is set to scrollX
you want a script to change scrollX so that the scrolling stays the same.
when key [left] pressed [change scrollX by (3)] when key [right] pressed [change scrollX by (-3)]
_____________________________________________________________________________
Then, if you want the mario style project, where the background only slides if the player is on the edge of the screen, and otherwise the player moves, you need to write a script that changes the x position of the player if their X position is greater than or less than a certain value, otherwise it changes the scrollX
That's quite simple, somthing like this:
when key [left] pressed IF <(X position of player) > (-200)> [change x by (-3)] ELSE [change scrollX by (3)] when key [right] pressed IF <(X position of player) < (200)> [change x by (3)] ELSE [change scrollX by (-3)]
something like that. I have done that second version myself but I find scratch handles it badly, and you move slower when you are scrolling the background than if you are scrolling along the edge.
I made a scrolling game AAAGES ago when I first started that you are welcome to examine and learn from.
Link to blob game
Offline
I see I have just been outdone by wolfie 1996, but that one has some nice screenshots that are easier to digest than my method. Feel free to learn from that game all the same, and good luck ^_^
Offline
Sorry about putting it in the wrong subject, I don't understand about the costumes for the terrain (do i have to have more than 1 costume or is that optional and if i must have more than 1, can those 2 terrains be the same?), And in some of archmages (for example) the terrain goes on for more than one screen, how could you do that?
Offline
blastoisedragon wrote:
Sorry about putting it in the wrong subject, I don't understand about the costumes for the terrain (do i have to have more than 1 costume or is that optional and if i must have more than 1, can those 2 terrains be the same?), And in some of archmages (for example) the terrain goes on for more than one screen, how could you do that?
You have to use multiple sprites (unless you're trying to make a 1s1s-er... but they're kind of hard to do... ), and add a different number into each multiplication block, in the order that you want them to go (the first one would be 1, then 2, then 3, etc).
Offline
blastoisedragon wrote:
Sorry about putting it in the wrong subject...
No worries, I'll move it over to the right area.
Offline
wei2912 wrote:
How do you do 4-way scrolling, then?
Alter the Scroll X scripts for Scroll Y. The Scroll X script and the Scroll Y script both have to be there!
Offline
Jonathanpb wrote:
wei2912 wrote:
How do you do 4-way scrolling, then?
Alter the Scroll X scripts for Scroll Y.
The Scroll X script and the Scroll Y script both have to be there!
![]()
Not quite, you have to combine both as well as understand how they works. Its a lot like a table with rows and columns. With scrollX the terrain number acts to put the sprite in its coluumn and the terrain number for scrollY acts to put the sprite in its correct row.
To see this in action download this: http://scratch.mit.edu/projects/archmage/100982
Offline
it did not work for me
Offline
Topic closed
Pages: 1