Jump to content

Make one function for all the states


AbdSab
 Share

Recommended Posts

Hi all, so i'm new in phaser, i've started learning it by making a project, so i have a problem :

 

I have more than one level for example 10 levels each one has it's own state, so the problem i don't want to make every time the same update function and other functions for every state.

 

So is there any way to make one function for all the 10 state ?

 

And thank's :)

Link to comment
Share on other sites

I had the same problem and did also choose the inheritance method.

Here's some code that could help:

 

The main Level "class" all Levels inherit from:

 

https://github.com/geibi/phaser/blob/master/js/Level.js

 

There i got some "parentCreate" and "parentUpdate" etc. function which are called by the child Level classes e.g.

https://github.com/geibi/phaser/blob/master/js/Levels/Level_2.js

 

Here you see e.g. in line 21

BasicGame.Level_2.prototype.update = function () {  this.parentUpdate();

and after the update, all other functions for this specific level are called

 

hope this helps :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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