christian.tucker Posted December 15, 2014 Share Posted December 15, 2014 The game that I'm working on is multiplayer and makes use of nodejs and socket.io -- Basically when a player disconnects from the server they are removed from the client, this is done through the below code:socket.on('player-disconnected', function(json) { networkPlayers[json.playerId].finalize(); delete networkPlayers[json.playerId];});Where:var networkPlayers = {};Inside the finalize() method of the player, the following code is executed:Player.prototype.finalize = function() { this.finalized = true; this.playerSprite.destroy(); this.text_floating_name.destroy();};This works flawlessly, except for one condition, When a player logs out / disconnects they're no longer handled and they're removed from all clients; However if the client has not been updated after the removal and another player is added I receive the following error: Opera:ncaught TypeError: Cannot read property 'cache' of nullFireFox:TypeError: this.game is null phaser.min.js:10More information points to this methodPlayer.prototype.stopWalking = function() { if(this.finalized == true) { this.playerSprite.animations.stop(); this.playerSprite.loadTexture('warrior'); }};which is called when a tween event finished; The error is reproduced by disconnecting the client (and therefor calling destroy()) on the sprite before the tween event is called. I wrapped it in a finalized check to try to stop the error from occuring but it didn't work, the error is specifically pointing to this line:this.playerSprite.loadTexture('warrior');I'm not exactly sure how to go about fixing this anymore, unless I should make the movementTween a prototype variable instead of a local function variable and do something with it that way. Note: The game doesn't freeze, only the rendering, the logic and input still continues to be processed and relayed over the network, but the canvas stops updating at this point. The reason I call loadTexture at the end is to set the sprite back to it's normal state after the animation is stopped. Link to comment Share on other sites More sharing options...
XekeDeath Posted December 15, 2014 Share Posted December 15, 2014 I would say that you need to stop the tween in the finalize function.Using the tween managers removeFrom function, and passing it the object that is currently tweening will stop the tween without calling the onComplete callback. Link to comment Share on other sites More sharing options...
Recommended Posts