Jump to content

State Management - a Tiny Tutorial


Nambiar
 Share

Recommended Posts

I've prepared a small tutorial for managing game states using Phaser. Its fairly straightforward to figure out yourself, but I'll just put it out there nonetheless. 

 

[Edit :- The earlier link was broken. You can find a copy (from memory) of the tutorial here - http://gamedolph.in/tutorials/state-management-tiny-tutorial/  ]

Link to comment
Share on other sites

I've prepared a small tutorial for managing game states using Phaser. Its fairly straightforward to figure out yourself, but I'll just put it out there nonetheless. 

http://s-nambiar.com/tutorials/managing-game-states-phaser/

 

Thanks for the tutorial. Something I'm still not clear on is what happens to the states vars etc when the game switches to another state? does the state manager delete things and clear everything up? or it doesn't and that's up to the developer to take of?

Link to comment
Share on other sites

Thanks for the tutorial. Something I'm still not clear on is what happens to the states vars etc when the game switches to another state? does the state manager delete things and clear everything up? or it doesn't and that's up to the developer to take of?

 

State-manager -> start()

 

The docs say that it does by default. Though there are other options too, like the destroy() and remove() too. Check them out :)

 

Edit :-

I ran a memory profile on one of my games, and this is what happened ...

5FGqZH3.png

 

So I guess it does what it claims :P

Link to comment
Share on other sites

State-manager -> start()

 

The docs say that it does by default. Though there are other options too, like the destroy() and remove() too. Check them out :)

 

Edit :-

I ran a memory profile on one of my games, and this is what happened ...

5FGqZH3.png

 

So I guess it does what it claims :P

I know it depends on how you have coded your game, but doesn't that graph show a slight increase in memory usage even after each state change?

Link to comment
Share on other sites

I know it depends on how you have coded your game, but doesn't that graph show a slight increase in memory usage even after each state change?

The fact that memory use drops at the exact same moment that I change state (different from the usual see-saw pattern during a state) seems to say that  a major mem change happened. Now, to pin point if it does what is expected, i'll have to open up the js file ... sooooo lazy...

Link to comment
Share on other sites

  • 4 months later...

I've prepared a small tutorial for managing game states using Phaser. Its fairly straightforward to figure out yourself, but I'll just put it out there nonetheless. 

http://s-nambiar.com/tutorials/managing-game-states-phaser/

 You're tutorial seems to not be there anymore. I tried clicking on the link and it just takes me a your WordPress page but not tutorial. :(

Link to comment
Share on other sites

  • 6 months later...

Thanks for the tutorial, will check it out as I need to learn more about this stuff.

 

I know it depends on how you have coded your game, but doesn't that graph show a slight increase in memory usage even after each state change?

 

Well, they're pretty close, but the other states might have more stuff in them, requiring more memory :P

Link to comment
Share on other sites

  • 2 months later...

Hi,

I just finished reading through the tutorial and I have some newbie questions.

 

First -in the tutorial you mention that a typical Phaser game is made up of these states:

 

"Now for the actual explanation. Matching Pairs is set up into 5 states -> Boot, Preloader, MainMenu, EndScreen and Game. "

 

In the latest version of the basic index.html on the Phaser repo, it only adds 4 game states - and leaves out EndScreen

 

https://github.com/photonstorm/phaser/blob/master/resources/Project%20Templates/Basic/index.html

 

So, I am assume that you don't need to add all of the game states, if you don't want to - that Phaser only actually uses the states you explicitly add/declare?

 

 

I understand how this passes control to the "Boot" function / state:

game.state.start('Boot'); //starting the boot state

 

What I do not understand is - in Boot.js there are multiple methods declared:

 

In the tutorial:  preload, create

In the repot version of Boot.js  https://github.com/photonstorm/phaser/blob/master/resources/Project%20Templates/Basic/Boot.js

these methods are declared:  init, preload, create

 

Sooo....  Is "init" optional since the tutorial does not declare it?

What determines the order in which these methods are called?

 

I assume they are being called automatically by the Phaser engine, once control passes to Boot?

 

I did search for "boot" through phaser.js - and didn't really find the answer to these questions - but I'm sure they are in the someplace, and I just don't recognize them...

https://raw.githubusercontent.com/photonstorm/phaser/master/build/phaser.js

 

I appreciate any enlightenment....

 

thanks

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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