ActionScript: Tutorial How to create a gravity like a Mario platformer

In this little tutorial you will learn how to create a gravity like a Mario platformer.

Let’s start!

Get files

  • Save these 2 sprites (Right click > Save as)

  • Open Flash and create a new ActionScript 3.0 document.
  • Document properties: 24 fps, 550×400 by default.

Create the Hero MovieClip

  • Create a new Symbol: Insert > New symbol > MovieClip
  • Symbol name: Hero
  • Check Export for ActionScript
  • And Click OK

  • Now you are in you Hero symbol! Perfect!
  • Import the first sprite: mario_stand.png on the first frame:
  • File > Import > Import to stage > mario_stand.png
  • Set the sprite just on the top of the little black cross (pivot point)
  • Now create an empty keyframe on the timeline:
  • Timeline > 2nd frame on the timeline > Right Click > Create empty Keyframe
  • Import the second sprite: mario_jump.jpg on the second keyframe
  • Then create a new layer on the top and set 2 labels names
  • Insert > Timeline > New layer
  • And add 2 labels names:
  • On the timeline click on the first key frame with the mario_stand.png sprite and go to the Properties pannel > Label > Name > stand
  • On the timeline click on the second key frame with the mario_jump.png sprite and go to the Properties pannel > Label > Name > jump

Add the jump script

  • Back to the main scene: Click on the Scene 1
  • Add a new layer named “Actions”: Insert > Timeline > New layer
  • And open the Actions pannel: Timeline > Actions Layer > Keyframe > Right click > Actions
  • Finally copy and paste this code:

Download sources: www.benoitfreslon.com_Create_gravity_like_a_mario_plateformer

8 thoughts on “ActionScript: Tutorial How to create a gravity like a Mario platformer

  1. salut vraiment beau tuto
    mais j’ai un probleme je fais tous ce que le tuto me dit de faire mais quand je lance l’animation il me dit sa:
    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 38: ‘)’ expected
    if (hero.y ; floor)

    **Error** Symbol=hero, layer=Layer 2, frame=1:Line 1: The class or interface ‘hero’ could not be loaded.

    Total ActionScript Errors: 2 Reported Errors: 2

    la source flash ne peux pas etre lancé caer je dois avoir un flash trop jeune ou trop vieux .
    merci d’avance de me repondre
    peux t’on me repondre sur mon adresse

    a++

  2. merci de m’avoir repondu aussi vite mais malgre avoir fait tous de que tu ma dis de faire sa marque toujours se:

    **Error** Symbol=hero, layer=Layer 1, frame=1:Line 1: The class or interface ‘hero’ could not be loaded.

    Total ActionScript Errors: 1 Reported Errors: 1

    qu’est se que veut dire “Petit problème d’un plugin de wordpress”
    Ensuite il faut mettre sur la scène un objet avec le nom d’occurence : hero
    Quelle objet???

    a++

  3. # Now you are in you Hero symbol! Perfect!
    # Import the first sprite: mario_stand.png on the first frame:
    # File > Import > Import to stage > mario_stand.png
    # Set the sprite just on the top of the little black cross (pivot point)
    # Now create an empty keyframe on the timeline:
    # Timeline > 2nd frame on the timeline > Right Click > Create empty Keyframe
    # Import the second sprite: mario_jump.jpg on the second keyframe
    # Then create a new layer on the top and set 2 labels names
    # Insert > Timeline > New layer
    # And add 2 labels names:

  4. Hello, très bon tuto bien expliqué, souvent rare, merci bien !!
    Je tien a préciser que pour le faire fonctionner sous flash 5 il faut remplacer
    if (hero.y > floor) par if (hero.y > floor)
    Voila !!

Leave a Comment