mercredi 6 mai 2015

Javascript Functioncall Socket.io and Phaser

I have a problem with a function call with Phaser. I am a Javascript Noob and don´t know what I do wrong.

Here is the critical Part of my Code, all the code is in the same file.

BasicGame.Multiplayer = function (game) {
};

  BasicGame.Multiplayer.prototype = {

        create: function(){
            this.socket = io.connect('localhost:3010');
            this.socket.on('startGame', function () {
                console.log('ShouldStartGame');
                this.createActualGame();
            });
},

createActualGame: function(){
        // Define constants
       }
}

My problem is that the function this.createActualGame is not called with the error: "TypeError: this.createActualGame is not a function". But the console log works fine.

Without the socket.on(...) the code works fine and the function is called with the statement "this.createActualGame()", but wihtin the socket.on(...) it doesn´t work and i have no clue why and no idea how this could be solved. Thank you very much for your help.

With kind regards, SirSandmann

Aucun commentaire :

Enregistrer un commentaire