Jump to content

Code structure (levels, states aso.)


ageibert
 Share

Recommended Posts

Hi forum members,

i'm a fresh phaser user since yesterday.

I read a whole bunch of tutorials, the docs and the examples.

I also looked at the huge gameslist with sourcecodes. But none of them fitted my imaginations of a nice app structure (without AMD). Very often i found huge repetition e.g. when handling levels.

 

So i created an own structure and i'd be very happy about critiques.

My test project is based on the famous star collecting tutorial and can be found here:

https://github.com/geibi/phaser

If you'd like to run it locally, you have to "bower install"

 

The "game" itsself is easy and ugly by now :) but functional for the purpose of code structure testing
- It gets preloaded

- then a "menu" with a start button follows -> click it

- level 1 gets loaded with platforms, the player and stars. the player can collect stars.

- if the player gots 3 stars, level 2 is automatically loaded

- in level 2, nothing happens except the player automatically gets points.

- if the player has more than 2000 points, the game automatically jumps back to the main menu

My code questions are:

 

- Is the basic structure and state changing ok?

- I "invented" a base Level(.js) class, from which all Level_(x) files inherit. In this base class all functions and actions, which are fired in every level, are stored and get called via the parent(Preload/Create/Update) methods in the child classes at the appropriate time.
I find this structure quite comfortable, because it eliminates repetition.

But are there any downsides with phaser? Maybe some automatic cleanup is failing or anything else?

 

Thanks for any infos and critique :)

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...