Sign in to follow this  
kate

Phaser login/signup form

Recommended Posts

Hi, I am developing a game in phaser but I am newbie yet. I want to create a login/signup/fb form in the main screen of the game. I did a html form in the index.html of phaser, but I have some doubts. How could I achieve the communication between the html and the scenes of phaser? I created global variables, but I think that is not a good practice.

Are there any options to use a state from html like MyGame.MainPage.startGame()?

This is the js script of the index, the function is associated to login button:

function login(){
    user = check_user_in_db();
    if(user){   //If the login is correct
        variable.startGame();
    }                  
}

This is the MainPage scene of Phaser:

/*********************NAMESPACE********************/
var MyGame = MyGame || {};
/**************************************************/

/******************INIT APP SCENE******************/
MyGame.MainPage = function(game)
{
    variable = this;
};

MyGame.MainPage.prototype =
{
    init: function()
    {

    }, // init

    preload: function()
    {
       //load Sprites
    }, //preload

    create: function()
    {
       //create Buttons 
    }, // create

    shutdown: function()
    {

    }, // shutdown

    startGame: function(){
        this.state.start("Menu", true, false);
    }
};

Share this post


Link to post
Share on other sites

You can use localStorage.

function login(){
    user = check_user_in_db();
    if(user){   //If the login is correct
        localStorage.setItem('login', JSON.stringify(user));
        variable.startGame();
    }                  
}

and then get it within your create method with

this.login = JSON.parse(localStorage.getItem('login'));

There is also a phaser-super-storage Plugin that can handle this for you with a fallback to cookies if the browser is very old.

Share this post


Link to post
Share on other sites

It's usually easiest to work with a reference to the current game (Phaser.Game). You can always reach the current state through that.

You could save a reference in your global

MyGame.game = new Phaser.Game(/*…*/);

and then call from login():

MyGame.game.state.start('Menu');
// OR
MyGame.game.state.getCurrentState().startGame()

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.