khleug35 Posted October 1, 2017 Share Posted October 1, 2017 here is my code <script> var game = new Phaser.Game(372, 635, Phaser.AUTO, 'game'); game.state.add('menu',menu); game.state.add('Level1',Level1); game.state.start('menu'); </script> //Level1.js var Level1 = { init: function() { this.play = true; <---------/*I want to call it in Enemy: function(){this.init = function()*/--> }, preload: function() { this.load.im.......... }, create: function() { this.enemy = new this.Enemy(); this.enemy.init(); }, update: function() { ........ }, Enemy: function(){ this.init = function (){ console.log(this.play); <-----------/*I want to call this.play = true, but it show undefined*/ if(this.play == true){ <-----------/*I want to call this.play = true, but it show undefined*/ dosomething..... }else{ dosomething..... } } I want to call "this.play = true; " in Enemy: function(){ this.init = function () but it is not successful......the chrome console is display show "undefined" How is it possible to call this function??? thx very much Link to comment Share on other sites More sharing options...
squilibob Posted October 2, 2017 Share Posted October 2, 2017 in your create function you never call this.init() so this.play never gets set to true before this.enemy is instantiated Link to comment Share on other sites More sharing options...
khleug35 Posted October 2, 2017 Author Share Posted October 2, 2017 1 hour ago, squilibob said: in your create function you never call this.init() so this.play never gets set to true before this.enemy is instantiated Thanks you very much!!! Link to comment Share on other sites More sharing options...
Recommended Posts