Jump to content

Including Player Control Methods into an Existing Game State


Recommended Posts

My current project uses game states, and I'm to the point where I have a character that can walk between different levels (states), but in every js file where my individual levels are I have all my code for player movement duplicated in each.

I'd like to make my code slimmer and more modular because I'm to the point where I'm getting some slow down/lag in chrome browsers, and I'd like to keep scaling my project and that isn't easy with all of this duplicate code in every state. For reference, the way my project is constructed is based off of this tutorial: http://www.emanueleferonato.com/2014/08/28/phaser-tutorial-understanding-phaser-states/

For example, if this were one of my level states:

theGame.prototype = {
   create: function(){
number = Math.floor(Math.random()*10);
spriteNumber = this.game.add.sprite(160,240,"numbers");
spriteNumber.frame = number;
var higherButton = this.game.add.button(160,100,"higher",this.clickedHigher,this);
var lowerButton = this.game.add.button(160,380,"lower",this.clickedLower,this);
clickedHigher: function(){
Link to comment
Share on other sites


  • Recently Browsing   0 members

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