ptotheaul Posted February 14, 2018 Share Posted February 14, 2018 I need to call to call a function in my game state from the Dom to toggle the audio of my game. Is this possible? In index.html the game is set up like this: //////// index.html ///////////////////////////////////////////////////////////////////////// var game; (function() { game = new Phaser.Game(640, 1195, Phaser.CANVAS, 'the-game'); game.state.add("Boot",boot); game.state.add("Preload",preload); game.state.add("TheGame",theGame); game.state.start("Boot"); })(); /////////////////////////////////////////////////////////////////////////////////////////////// After preload this.game.state.start("TheGame"); is called to load the game. The function I need to call from a button in the DOM is funcFromDom /////////////////////////////////////////////////////////////////////////////////////////////// var theGame = function(game){ }; theGame.prototype = { create: function(){ console.log("create()") }, funcFromDom: function(){ console.log("called from the dom"); }, } Link to comment Share on other sites More sharing options...
ptotheaul Posted February 14, 2018 Author Share Posted February 14, 2018 In case anyone else is looking for the answer to this I figured it out. From the DOM you can just call: game.state.states[game.state.current].funcFromDom(); Link to comment Share on other sites More sharing options...
Recommended Posts