Jump to content

Phaser's States vs Quintus Scenes


Recommended Posts

is there anyway to carry out a game state in phaser similar to how Quintus handles scenes for handling loading screens, levels, and such?


here is how quintus creates a level or scene.


// Create a new scene called level 1Q.scene("level1",function(stage) {// Add in a tile layer, and make it the collision layer  stage.collisionLayer(new Q.TileLayer({                            dataAsset: 'level.json',                            sheet: 'tiles' }));// Create the player and add him to the stage  var player = stage.insert(new Q.Player());// Give the stage a moveable viewport and tell it // to follow the player.  stage.add("viewport").follow(player);// Add in a couple of enemies  stage.insert(new Q.Enemy({ x: 700, y: 0 }));  stage.insert(new Q.Enemy({ x: 800, y: 0 }));  // Finally add in the tower goal  stage.insert(new Q.Tower({ x: 180, y: 50 }));});

and loading a scene is as simple as

// When the button is clicked, clear all the stages // load scene / levelbutton.on("click",function() {     Q.clearStages();     Q.stageScene('level1'); });

the quintus site has a detailed interactive example so you can see what im talking about.




maybe phaser can do something like:

function Level_1() {    game.stage.backgroundColor = '#262524';    // add entities to game level    player = game.add.sprite(300, 200, 'player');    baddy = game.add.sprite(800, 400, 'baddy');    // add goal to game level    trophy = game.add.sprite(900, 800, 'trophy');    // player cant leave game world bounds    player.body.collideWorldBounds= true;    // add gravity to player    player.body.gravity.y = 10;} 
 function collisionHandler (player, trophy) {     // if a collision occurs between the player and trophy    // play chirp sound one time, if player collects trophy    chirp.play();    // load next level.    Phaser.load(Level_2);                                   }// this is the end of the collision handler  }          

ps. i made the above code up as i typed. And yes iv gone through the examples in the phaser basic template to see how phaser handles game states.


creating scenes or states in quintus is really quick and simple but i enjoy using making games in Phaser . Is there anyway to do something similar in Phaser to create loading screens and change levels? 


or will phaser add more ways to handle scenes and states are will it start handling scenes and states differently in the future? 

Link to comment
Share on other sites

Phaser and Quintus operate in different manners, but you can accomplish the same thing

var level2 = {  preload: function() { /* load assets */ },  create: function() {    // borrowing from your example...    game.stage.backgroundColor = '#262524';    player = game.add.sprite(300, 200, 'player');    baddy = game.add.sprite(800, 400, 'baddy');    player.body.collideWorldBounds= true;    // add gravity to player    player.body.gravity.y = 10;    // add controls, set camera, yada yada yada  },  update: function() { /* game logic */ }};game.state.add( 'level2', level2, true );
Link to comment
Share on other sites

(er, obviously you'd want to implement preload() and update() so they actually did something)

lol yea i know i just wanted to give a quick and basic example focused on making scenes/states. Wouldn't it be a waste to keep typing the same player controls into the update function though. i was just planning on adding controls and stuff to the main game loop and having phaser swap out and load up the assets and preloads /creates from each level.

for example if i used the same exact player and enemy sprites that i had loaded in the main preload function. couldn't i just reuse them into a new level without having to add them to my level preload all over again? all i would really have to preload into the next level would be music and tiles maps.



or am i missing something here?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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