carlos95 Posted July 18, 2014 Share Posted July 18, 2014 Hello,I post in this forum because i need help with 4 lines of code that doesnt work in my game.js file. The similiraty of this 4 lines is that the last method parameter is a this. In the phaser-examples they say that this parameter is: "the context under which that will happen", leaving it as a 'this'. Well, i dont know if thats the real problem or there is something im not realising. Here i leave the lines of code found in the create function that doesnt work (the rest of it do work perfectly when I deleate the lines): // The camera follows the player this.camera.follow(player); // ----------- error------------- // The timer. After 20 seconds its game over. // this.time.events.add(Phaser.Timer.SECOND * 20, gameOver,this) // full screen this.stage.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT; // -----------error--------------- // this.input.onDown.add(fullScreen, this); //-----------error---------------- // We create a body specific callback // player.body.createBodyCallback(paper, hitPaper, this); // Turn on impact events for the world. this.physics.p2.setImpactEvents(true); Thank you very much Link to comment Share on other sites More sharing options...
lewster32 Posted July 18, 2014 Share Posted July 18, 2014 Yes, this is a scope issue. Without seeing the rest of your code for the state however, I can't advise as to the correct context to pass. Link to comment Share on other sites More sharing options...
carlos95 Posted July 18, 2014 Author Share Posted July 18, 2014 Here it is Game.txt Link to comment Share on other sites More sharing options...
lewster32 Posted July 18, 2014 Share Posted July 18, 2014 Ah ok, so you're using the standard templates. In this case, you need to add 'this.' to your callbacks, like so:this.time.events.add(Phaser.Timer.SECOND * 20, this.gameOver, this); Link to comment Share on other sites More sharing options...
carlos95 Posted July 18, 2014 Author Share Posted July 18, 2014 Thank you very much!! it works now lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts