neurofuzzy Posted October 19, 2014 Report Share Posted October 19, 2014 I have a button with a callback that effectively completes a state and moves on to the next state. The world remains but I remove the UI (including that button). The problem is, it seems that the callback fires on mouseup, but before the button changes back to the up state. So, when the button is removed using button.destroy(), it causes null reference errors:Uncaught TypeError: Cannot read property 'cache' of nullIt is referencing this.game.cache, but this.game is null. I could fork Phaser and fix this, but I was wondering if maybe I'm just doing it wrong. Thanks! Quote Link to comment Share on other sites More sharing options...
Juholei Posted March 27, 2015 Report Share Posted March 27, 2015 I encountered this issue now myself. Below is the code from my project.var PointEditScreen = function(game) { Phaser.Image.call(this, game, 600, 50, 'background'); var exitButton = game.add.button(360, 5, 'exit-button', this.closeScreen, this, 1, 0, 2, 0); this.addChild(exitButton);PointEditScreen.prototype.closeScreen = function() { this.destroy();};The code works, but results in the same error as with the original poster: "Uncaught TypeError: Cannot read property 'cache' of null". The error does not happen if don't I give any values to downFrame and upFrame when creating the button. Also, if I set the downFrame and upFrame to the same value, in my case the frames would then be 1, 0, 2, 2, the error does not occur. So is this a bug or am I doing something wrong? Edit: Seems to be fixed in Phaser 2.3.0. My problem was with 2.2.2. Great Quote Link to comment Share on other sites More sharing options...
Aymeric Posted April 16, 2015 Report Share Posted April 16, 2015 Sounds like there are still some issues with Phaser 2.3.0 https://github.com/photonstorm/phaser/issues/1748 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.