frokenstein Posted June 7, 2015 Share Posted June 7, 2015 This is a game that used to work. I moved some of the vars into the player object because that's where they belong. But I believe I've created a scoping problem or something related. The player sprite is now invisible and physics is no longer enabled. I cannot see where the issue is. There is a map sprite which is part of the player sprite and that is visible. It's very odd. I think it's something simple but I cannot seem to find the culprit: The player gets instantiated as follows:this.player = new Player(this, this.earth.x, this.earth.y);The player object looks like this:var Player = function(main, x, y, frame){this.playerScale = main.GAME_SCALE;var key = 'player';Phaser.Sprite.call(this, main.game, x, y, key, frame);this.anchor.setTo(0.5);this.scale.setTo(this.playerScale * 1.6);this.MAXHEALTH = 100;this.MAXCHARGE = 100;this.MAXTURNINCREMENT = 0.1;this.MAXTURNRATE = 4;this.MINTURNRATE = 0.8;this.WARP_DISCHARGE = 0.2;this.SHIELD_DISCHARGE = 4;this.MAXVELOCITY = this.playerScale * 3500;this.WARPVELOCITY = this.playerScale * 16;this.MAXTHRUST = this.playerScale * 50;this.health = this.MAXHEALTH;this.charge = this.MAXCHARGE;this.thrust = this.MAXTHRUST;this.turnRate = 0;this.maxTurnRate = this.MAXTURNRATE;this.turnIncrement = this.MAXTURNINCREMENT;this.maxVelocity = this.MAXVELOCITY;this.shieldStrength = this.MAXCHARGE;this.warpDrive = this.MAXCHARGE;this.warpModifier = 5;this.isAlive = true;this.isReloaded = true;this.isBurning = false;this.isWarping = false;this.isShielded = false;main.game.physics.arcade.enableBody(this);this.body.bounce.set(0.8);this.checkWorldBounds = true;this.body.collideWorldBounds = true;this.begin = true;this.nukes = 0;this.missiles = 0;this.hasShields = false;// Set player mapthis.map = main.game.add.sprite(main.width - main.mapSize - main.mapOffset + parseInt(this.x * main.mapGameRatio), parseInt(this.y * main.mapGameRatio) + main.mapOffset, 'playermap');this.map.fixedToCamera = true;this.map.anchor.setTo(0.5);this.map.scale.setTo(2);// Set player animationsthis.animations.add('drift', [0]);this.animations.add('shield', [1]);this.animations.play('drift', 20, true);this.map.animations.add('tracking', [0,1]);this.map.animations.play('tracking', 10, true);};Player.prototype = Object.create(Phaser.Sprite.prototype);Player.prototype.constructor = Player;Player.prototype.onRevived = function() {this.health = this.MAXHEALTH;this.turnIncrement = this.MAXTURNINCREMENT;this.maxVelocity = this.MAXVELOCITY;this.maxTurnRate = this.MAXTURNRATE;this.thrust = this.MAXTHRUST;this.isBurning = false;this.warpDrive = this.MAXCHARGE;};I have console logged this object and there are no NaN or undefined properties, so it seems like everything is getting in there, but the player ship does not appear and is no longer supporting physics. What stupid thing have I done here? You can see the game here:joelsaxton.github.io/starpatrol The repo is here:https://github.com/joelsaxton/starpatrol PS - do you have a paid support option yet? Link to comment Share on other sites More sharing options...
Eraph Posted June 8, 2015 Share Posted June 8, 2015 Did you add the sprite object to the game? After:this.player = new Player(this, this.earth.x, this.earth.y); Add:this.game.add.existing(this.player); Tilde 1 Link to comment Share on other sites More sharing options...
frokenstein Posted June 8, 2015 Author Share Posted June 8, 2015 This seems to have worked. Strange, though: this.game.add.existing wasn't needed for my other sprites. Tilde 1 Link to comment Share on other sites More sharing options...
drhayes Posted June 8, 2015 Share Posted June 8, 2015 Were they added to a group? When you add a group via "game.add.group" they get added to the world automatically. Any sprite you add to one of these groups is thus in the world, too. Link to comment Share on other sites More sharing options...
frokenstein Posted June 8, 2015 Author Share Posted June 8, 2015 That's it! Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts