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

#1 2010-02-23 21:37:39

TMFOS
Scratcher
Registered: 2009-05-30
Posts: 4

getting caught up in the annoyances of making a platformer

I've managed to figure out how to animate with scratch easily enough, and attaching things like charge attacks as variables, but I can not for the life of me figure out how to get a character onto a platform, or stay on any ground for that matter. In other words, how do I create gravity with scratch?

Offline

 

#2 2010-02-24 05:26:14

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: getting caught up in the annoyances of making a platformer

If the ground is a certain color, you can have the sprite check if it's touching that color - and if it isn't, then you can have the sprite fall. If the ground doesn't stay as one color, you could make the ground a sprite and have the sprite check if it's touching that sprite.

For having velocity in falling, here's a script that might help - adapt it to your needs.

http://img46.imageshack.us/img46/5121/50asimplefallingscriptw.png

Any questions?

Last edited by Jonathanpb (2010-02-24 05:27:33)


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#3 2010-02-24 05:31:22

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: getting caught up in the annoyances of making a platformer

and after jonathns script add set velocity to zero too else he will dig himself in grnd


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#4 2010-02-24 06:29:12

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: getting caught up in the annoyances of making a platformer

That actually isn't neccessary - before the falling script starts the variable gets set back to 0. And the falling script stops when the sprite touches the ground.  wink

Last edited by Jonathanpb (2010-02-24 06:31:33)


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#5 2010-02-24 19:38:37

TMFOS
Scratcher
Registered: 2009-05-30
Posts: 4

Re: getting caught up in the annoyances of making a platformer

the only problem I've found with that though, is the character will sink into the ground a couple pixels every now and again after they jump. oh, and another thing, how do i make a scrolling screen?

Offline

 

#6 2010-02-25 02:33:41

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: getting caught up in the annoyances of making a platformer

The jumping script I showed is rather basic - the sprite won't be on the exact top of the ground most of the time. The accuracy is normally good enough, though. If it isn't, then add this script onto the end of the first script:

http://img191.imageshack.us/img191/6909/54afterthefallingscript.png
Input the correct Y position!

That script only works if the ground is always at the same level. But what if the ground level changes? Then you use this script:

http://img19.imageshack.us/img19/7175/55afterthefallingscript.png
Input the right colors - one color is the color of the bottom of the sprite, and the other is the color of the top of the ground. This script will work best if the color on the bottom of the sprite is only one pixel, and in the middle of the bottom of the sprite. You won't have to worry about that if the ground stays level, though.


About the scrolling: I wrote something a while ago, and I'll go and paste that in here:

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.

http://img171.imageshack.us/img171/6475/39twospritescrolling.png

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.

http://img697.imageshack.us/img697/3214/40manyspritescrolling.png

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:

http://img194.imageshack.us/img194/2497/41scrollxmovingscripts.png

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)

Any questions?

Last edited by Jonathanpb (2010-02-25 02:35:55)


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#7 2010-02-28 11:16:01

12368
Scratcher
Registered: 2010-02-25
Posts: 10

Re: getting caught up in the annoyances of making a platformer

There is also another way to make a platformer game.
And that way is this:

[blocks]
<when green flag clicked>
<forever>
<if> <touching color[ black
<change y by( -2
<if> <<  <not> <touching color[ black  >>
<change y by( 2
[/blocks]

I hope this helps.  smile

Last edited by 12368 (2010-02-28 11:38:48)

Offline

 

#8 2010-02-28 11:23:30

12368
Scratcher
Registered: 2010-02-25
Posts: 10

Re: getting caught up in the annoyances of making a platformer

And to answer your gravity question, you need to make a "yvelocity" variable.
Here is the script I used:
[/blocks]
<when[ space ]key pressed>
<go to x sad  0 )y sad  0
<set{ yvelocity }to( 0
<forever>
<repeat until><touching[ Ground
<change{ yvelocity }by( -1
<change y by( <{ yvelocity }>
<repeat until><( <{ yvelocity }> <=> 0 )>
<change{ yvelocity }by( 1
<change y by( <abs( <{ yvelocity }>
[/blocks]

Note**: The "abs" means absolute value. In other words, if you have a negitave number in the box, it turns it into a positive number.
I hope this helps too  smile
2nd Note**: The second "repeat until" block is NOT inside the first. Put the second "repeat until" block on the OUTSIDE of the first. So many people messed this up when I told them this. That is why i caps locked.
3rd Note**: Use this script ONLY if you want the sprite to bounce when it touches the ground.
4th Note**: (In conjunction with the 3rd Note) Adapt this script to your needs.

Last edited by 12368 (2010-02-28 11:44:15)

Offline

 

Board footer