Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Best way to do scenes?


Ryan
 Share

Recommended Posts

Hey guys,

 

I've been reading through the docs trying to find the best way to do scenes, such as 'preloeader', 'menu', 'game' etc. that act in the same way they do in Flash.

 

Do I create different stages for each scene?  Do I create a group for each scene and simply hide and show the one I need?

 

Any thoughts are welcome.

 

Thanks!

 

FyreTale

Link to comment
Share on other sites

Hey guys,

 

I've been reading through the docs trying to find the best way to do scenes, such as 'preloeader', 'menu', 'game' etc. that act in the same way they do in Flash.

 

Do I create different stages for each scene?  Do I create a group for each scene and simply hide and show the one I need?

 

Any thoughts are welcome.

 

Thanks!

 

FyreTale

 

I'm completely new to Phaser, but from what I've read so far my approach is just going to be use groups like you suggested, and throw everything that's needed into a group and then add/remove them when needed.

Link to comment
Share on other sites

Doesn't the basic template already separate the different states using individual objects? The difference between the tutorial (not using states) and the basic template is how the objects are accessed I think. In the tutorial they are all called in the original game object using the preload, create, and update methods. In the basic template the objects are called by initiating the state.

 

game.state.add('Boot', BasicGame.Boot);

game.state.add('Game' BasicGame.Game);

game.state.start(Boot);

 

The state 'Boot' is initialized after running the start method, then within the Boot object you define your current state, and can move again to another state/object by referencing the next defined state to start. Instead of referencing all of the objects within the game, you are running each object independently or calling them based on your states requirements. If your game state requires an object not loaded, then you could use the example in the tutorial and run the preload method within your current states preload.

 

This is as much for my education as yours, this is my interpretation so far, so if I am wrong I look forward to a better explanation. 

Link to comment
Share on other sites

Doesn't the basic template already separate the different states using individual objects? The difference between the tutorial (not using states) and the basic template is how the objects are accessed I think. In the tutorial they are all called in the original game object using the preload, create, and update methods. In the basic template the objects are called by initiating the state.

 

game.state.add('Boot', BasicGame.Boot);

game.state.add('Game' BasicGame.Game);

game.state.start(Boot);

 

The state 'Boot' is initialized after running the start method, then within the Boot object you define your current state, and can move again to another state/object by referencing the next defined state to start. Instead of referencing all of the objects within the game, you are running each object independently or calling them based on your states requirements. If your game state requires an object not loaded, then you could use the example in the tutorial and run the preload method within your current states preload.

 

This is as much for my education as yours, this is my interpretation so far, so if I am wrong I look forward to a better explanation. 

 

In the example I linked to though the dev has actually created objects for the Player, Level and HUD, so I was wondering how to incorporate that into the basic template, I'm sure it's straightforward but seeing I'm new to JS I wondered if anyones already combined those.

Link to comment
Share on other sites

  • 3 years later...

Instead of putting all your code in the main game loop, just create separate "classes" for each scene and then implement a Scene Manager to invoke the correct object function based on the current scene.

 

Recently, while using the p5.js library, I face this issue... So I created a p5.js Scene Manager logic to allow developers switch between scenes:

http://www.codeavenger.com/2017/02/27/p5-SceneManager.html

 

Of course ... you can implement this concept regardless if you are using p5.js or not.

Example: The following objects contain each scene setup and main loop functions (e.g. setup and draw):

 

function Intro()
{
    this.setup = function() {
    }

    this.draw = function() {
    }

    this.keyPressed = function() {
        this.sceneManager.showScene( Game );
    }
}

function Game()
{
    this.setup = function() {
    }

    this.draw = function() {
    }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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