Zampano Posted October 24, 2017 Share Posted October 24, 2017 Hello, I just updated from Phaser 2.8.0 to 2.9.1 and I've got some complications that I don't know how to solve best. I'm using states in different js files with the object BasicGame to hold the states. In BasicGame.Play I create various items of a certain sprite class I wrote. Until now, I did it like this: var c = new x_collectible(this); So "this" is an instance of BasicGame.Play. With the new update, I got an error along the lines of "The value passed as the `game` argument ([object Object]) is not an instance of Phaser.Game.". I went ahead and tried to change it to: var c = new x_collectible(this.game); It worked, but now I'm having trouble accessing functions or variables of my BasicGame.Play state from within the collectible class. Before I used "this.game.variable" or "this.game.function()". What would be a proper solution to this? Adding BasicGame to the arguments when creating a collectible? Adding an isntance BasicGame as an attribute to my Phaser.Game and then do "this.game.BasicGame.Play.variable"? These don't really seem very practical to me... Link to comment Share on other sites More sharing options...
samme Posted October 24, 2017 Share Posted October 24, 2017 What is happening in the x_collectible constructor? Link to comment Share on other sites More sharing options...
Zampano Posted October 24, 2017 Author Share Posted October 24, 2017 function x_collectible(game) { Phaser.Sprite.call(this, game, 0, 0, "x_collectibles", 0); this.anchor.setTo(0.5); this.value = 0; this.game.physics.enable(this); this.body.setCircle(17,3,3); this.sfx = {}; this.sfx["heart"] = this.game.sfx_collectibles["heart"]; this.sfx["superheart"] = this.game.sfx_collectibles["superheart"]; this.sfx["mine"] = this.game.sfx_collectibles["mine"]; this.sfx["ice"] = this.game.sfx_collectibles["ice"]; this.kill(); }; x_collectible.prototype = Object.create(Phaser.Sprite.prototype); x_collectible.prototype.constructor = x_collectible; the "this.game." calls are those that I don't know how to fix after the change. Link to comment Share on other sites More sharing options...
samme Posted October 24, 2017 Share Posted October 24, 2017 If you just need to reach the current state, you can do function x_collectible(game) { // … this.state = this.game.state.getCurrentState(); // … } and thereafter, e.g., // in x_collectible this.state.property If you get confused, just do console.log(this.game, this.state) to see what's what. Zampano 1 Link to comment Share on other sites More sharing options...
Zampano Posted October 25, 2017 Author Share Posted October 25, 2017 Ah, nice, thank you! (For the record, it's this.game.state.getCurrentState();) samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts