Jump to content

Game architecture - Your advice ?


Filozofer
 Share

Recommended Posts

Hi !

 

I'm trying to test thing we can do with phaser. My purpose was to found a way to have "Models" which contains all a component logic (player, button, ...).
I've succeed doing like this:

 

 //Create function of my MenuState object (just creating a button here) create: function ()   {                this.buttonsMenu = this.add.group();        var button = new ButtonMenu(this, this.make.button());        this.buttonsMenu.add(button); },
//My basic button menu object allowing me to keep method and attributes here and not in my state object var ButtonMenu = function (game, button) {            //Set methods on the phaser object (is this dirty ?)        button = constructor(this, button);        //Keep game reference        this.game = game;        //Load attributes and set button params        button.reset(this.game.world.centerX - 95, 400);        button.loadTexture('buttons_menu');        button.setFrames('button_hover.png', 'button_up.png', 'button_click.png');        button.onInputUp.add(button.alert, button);        button.anchor.set(0.5);        button.scale.set(2);        return button;};function constructor(plan, obj){     for(var m in plan) {         obj[m] = plan[m];     }     return obj; }   ButtonMenu.prototype.alert = function(){    alert('test');};ButtonMenu.prototype.update = function(){    this.angle += 1;};

What do you think of this way to do thing ? Can I do better ? Is my way to do that will be a problem for later ?

Thanx !

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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