Creation of a platform game using FlashPunk – Title screen

Every game should start at least with a simple title screen, and that’s what we are going to do with our FlashPunk project.

This is what you’ll get at the end of this step:

Press X to start playing then move the player as see in the second step.

Let’s see the logic behind it. Now we have the main game and the title screen.

Although managing the title screen as an Entity of the main world, I prefer to keep the title screen and the game itself in two different worlds.

This is what flashpunk class becomes

Unlike in the second step, I am giving a different background color (line 10) and I am assigning mainMenu as world (line 11).

So everything lies in the mainMenu class:

Basically here we need to display two texts: the game name and the classic “Press X to Start” you can see in most FlashPunk games. Then we need to detect when the player presses X and make him play.

Lines 10-14 add the “Press X to Start” text, using the Text class and its constructor (line 10) with the text to be rendered. Then we need to create an Entity containing such text element (line 11), center the text in the middle of the screen (lines 12-13, quite easy to understand) and finally the Entity is added to the world (line 14).

We can also define the color of the text, like I did with the name of the game (line 16) and its size (line 17) but if we change its size making it bigger than the default value (16), we will need to define its width and height, in pixels (the latest two arguments at line 15).

And now we are done with the texts.

update function at lines 23-28 checks for the player to press X and then changes screen color and initializes the world to the “game” world we met during step 2.

  • Ma’name

    10x for the tut.

    The main problem that I have with FP is to handle properly collisions whem I’m using mouse movements…
    I’ll continue to try

  • You forgot to call super.update(); :D

  • Rennan

    I liked this tut a lot.
    Thanks Emanuele for show to us this tip.
    Will you make a “How to do a complete game” series with Flash Punk?
    If you will, Not just I, but, I think it will be so cool!

    Regards.

  • Hi Emanuel, is possible another text type, I mean a non pixelate style?

    Thank you.

  • Denver

    Hi Emanuel,

    I liked it a lot. I was wondering, why donĀ“t you used buttons like a simple flash game? Does Flash Punk has its contents?

  • jeanpier

    Hi Emanuele,

    The FlashPunk tutorials are using version 1.4 of the library… doesn’t work on the last flashpunk version (1.5).

    For example: moveBy() function was removed.

    Thanks,

    Jean Pier