frokenstein

Members
  • Content Count

    39
  • Joined

  • Last visited

Everything posted by frokenstein

  1. I've tried everything I could think of in the shutdown() function but when I restart a game I cannot get it to restart in the same state it was in when I first loaded it in my browser. When my game ends there is a prompt to restart and when the user clicks the mouse, this function is called: this.game.state.start('Game', true, false);It seems to do its job but for whatever reason the alien ship sprite and its accompanying map sprite are invisible despite the fact that I can verify they're created. Not incidentally, this is the same function that starts the game the first time. I am perplexed why the exact same function wouldn't work the same way when called a second time. You can see it in action here: http://joelsaxton.github.io/starpatrol/ I've tried about six different ways to shutdown() the game but to no avail. My guess is the sprites are not being added to the game object (or something?) but I have to wonder why the same function which sets up the game would do it differently the second time it runs.
  2. Figured it out. this.engineBuyIcon.inputEnabled = true;this.engineBuyIcon.events.onInputDown.add(this.buyItem, this);
  3. What is the simplest way to do this? Right now I am binding a function whenever the mouse is clicked: game.input.onDown.add(this.clickOnItem, this);This function figures out the x,y location of the click but what is the easiest way to determine if it is above a particular icon? Do I need to write an overlap function for every single icon it may overlap/collide with?
  4. This seems to have worked. Strange, though: this.game.add.existing wasn't needed for my other sprites.
  5. 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?
  6. Is it possible to make a scrolling game using the isometric plugin? Or is it static? I am curious if there are any examples out there. Thanks
  7. I make a heat seeking nuke in my game. I utilize this function to help it track its target: this.game.physics.arcade.angleBetween(nuke, this.alien)When the nuke is launched and the target is to the right of it, it tracks fine. But if the target is to the left, the nuke just oscillates slightly and doesn't turn all the way around to move toward its target. Does angleBetween not take this into account?
  8. I am trying to chain tweens then run an onComplete once the final tween runs. Unfortunately Phaser ignores the fist tween. Any ideas why? var tween = this.add.tween(this.alien).to({x: 500, y: 500}, 3000, Phaser.Easing.Linear.None).to({x: 0, y: 0}, 3000, Phaser.Easing.Linear.None).start();tween._lastChild.onComplete.add(function(){this.alien.isAttacking = true;}, this);Once the tween is triggered the sprite goes to x: 0, y: 0 and completely ignores the first directive to go to x: 500, y: 500. I am using Phaser 2.2.0 RC7 and I'm wondering if there is a bug here.
  9. Well, it was working. I broke the fiddle. Working on it...
  10. You can also see it in its full glory here (with debugger on): http://joelsaxton.github.io/starpatrol/ I created a fiddle but it is very stripped down, and, unfortunately, it works: http://jsfiddle.net/joeljoelbinks/v0ojvuh9/ I will need to keep adding stuff back until I can get it to fail. This is a really weird problem.
  11. Two places. First at the beginning of the game. This creates an alien that works. ...and in the update() function. If an alien was killed, after a timer event a new one is created here: if (this.alienTimer < this.game.time.now) {this.alienTimer = this.game.time.now + this.alienInterval;if (this.aliens.countLiving() < this.TOTALALIENS) {this.createAlien();}}I have verified the second alien is created, but it has NaN for rotation, x, y, etc. But its health is back to 100, its alive is true, and the other indications if it being alive look correct. It just never appears on the screen. It seems to be some kind of ghost object but I cannot see what is missing.
  12. Sorry to post here again, but I ran into another weird issue. My function for creating an alien sprite is as follows: createAlien: function() {this.alien = this.aliens.getFirstDead();var start = this.game.rnd.integerInRange(1, 4);switch (start) {case 1:var x = this.game.world.bounds.width;var y = this.game.rnd.integerInRange(0, this.game.world.bounds.height);break;case 2:var x = 0;var y = this.game.rnd.integerInRange(0, this.game.world.bounds.height);break;case 3:var x = this.game.rnd.integerInRange(0, this.game.world.bounds.width);var y = this.game.world.bounds.height;break;case 4:var x = this.game.rnd.integerInRange(0, this.game.world.bounds.width);var y = 0;break;}if (!this.alien) {this.alien = new Alien(this.game, x, y, this.MAXCHARGE, this.MAXHEALTH, this.alienScale);this.aliens.add(this.alien);}this.alien.reset(x, y);this.alien.revive();}As you can see, I am generating the x, y for a new and a revived alien. When I create the first new alien, it works fine, but after that alien dies and I revive the sprite, both x and y show up as NaN. I am trying to figure out why but I am at a loss. What did I do wrong? Here is my alien class: var Alien = function(game, x, y, charge, health, scale, key, frame){key = 'alien';Phaser.Sprite.call(this, game, x, y, key, frame);this.anchor.setTo(0.5);this.scale.setTo(scale);this.maxcharge = charge;this.maxhealth = health;this.charge = this.maxcharge;this.health = this.maxhealth;this.alive = true;game.physics.arcade.enableBody(this);this.body.collideWorldBounds = false;this.body.bounce.set(1);this.events.onRevived.add(this.onRevived, this);};Alien.prototype = Object.create(Phaser.Sprite.prototype);Alien.prototype.constructor = Alien;Alien.prototype.onRevived = function() {this.charge = this.maxcharge;this.health = this.maxhealth;this.alive = true;};Isn't reset() supposed to take an x and y coordinate and plug it into the object? When I console log the alien position I always get NaN for both coordinates for the revived alien. The first alien to be constructed works fine.
  13. I decided to check no world bounds at all and just destroy() a bullet once it reaches an "expiration time".
  14. Cool, thanks. BTW That Isometric Plugin looks dope, Lewster. Gonna try it out once I have an idea worth trying it out on.
  15. I have a game that runs fast for several minutes then gradually gets more and more sluggish. I've tried profiling in Firebug but it just beachballs and renders the browser unusable. I feel like my only option is to throw in console.logs and see if I can hunt for what is getting out of hand. If anyone has any suggestions please let me know. Thanks
  16. This is the solution. Asteroid obj: var Asteroid = function(game, x, y, direction, key, frame){key = 'asteroid';Phaser.Sprite.call(this, game, x, y, key, frame);this.scale.setTo(this.game.rnd.realInRange(0.1,0.5));this.anchor.setTo(0.5);this.game.physics.arcade.enableBody(this);this.direction = direction;this.events.onRevived.add(this.onRevived, this);this.maxUpperVel = 600;this.maxLowerVel = 200;this.maxAngularVel = 400;};Asteroid.prototype = Object.create(Phaser.Sprite.prototype);Asteroid.prototype.constructor = Asteroid;Asteroid.prototype.onRevived = function() {switch (this.direction) {case 1:this.body.velocity.x = this.game.rnd.integerInRange(-this.maxUpperVel,-this.maxLowerVel);this.body.velocity.y = this.game.rnd.integerInRange(-this.maxLowerVel,this.maxLowerVel);break;case 2:this.body.velocity.x = this.game.rnd.integerInRange(this.maxLowerVel, this.maxUpperVel);this.body.velocity.y = this.game.rnd.integerInRange(-this.maxLowerVel,this.maxLowerVel);break;case 3:this.body.velocity.y = this.game.rnd.integerInRange(-this.maxUpperVel,-this.maxLowerVel);this.body.velocity.x = this.game.rnd.integerInRange(-this.maxLowerVel,this.maxLowerVel);break;case 4:this.body.velocity.y = this.game.rnd.integerInRange(this.maxLowerVel, this.maxUpperVel);this.body.velocity.x = this.game.rnd.integerInRange(-this.maxLowerVel, this.maxLowerVel);break;}this.body.angularVelocity = this.game.rnd.integerInRange(0, this.maxAngularVel);};Create asteroid function: createAsteroid: function () {var start = this.game.rnd.integerInRange(1, 4);switch (start) {case 1:var x = this.game.world.bounds.width;var y = this.game.rnd.integerInRange(0, this.game.world.bounds.height);var direction = 1;break;case 2:var x = 0;var y = this.game.rnd.integerInRange(0, this.game.world.bounds.height);var direction = 2;break;case 3:var x = this.game.rnd.integerInRange(0, this.game.world.bounds.width);var y = this.game.world.bounds.height;var direction = 3;break;case 4:var x = this.game.rnd.integerInRange(0, this.game.world.bounds.width);var y = 0;var direction = 4;break;}var asteroid = this.asteroids.getFirstDead();if (!asteroid) {asteroid = new Asteroid(this.game, x, y, direction);asteroid.checkWorldBounds = true;asteroid.outOfBoundsKill = true;this.asteroids.add(asteroid);}asteroid.reset(x, y);asteroid.revive();},Loop to run createAsteroid() function to create pool of asteroids at beginning of game: while (this.asteroids.countLiving() < this.TOTALASTEROIDS) {this.createAsteroid();}using countLiving() seems to be what helped. I no longer need an extra var/function to track how many are alive.
  17. I have a game where the world bounds extend far beyond the screen. I have a sprite set to accelerateToObject() to another sprite. This accelerating sprite is set like so: this.checkWorldBounds = true;this.outOfBoundsKill = true;What I am seeing is really strange. Because the sprite accelerates, it can sometimes fly offscreen. This was anticipated, and isn't an issue. But what I see is when the sprite flies offscreen to the top or the left, it is killed even if it is not outside the world bounds. Even stranger, when it flies off to the right or the bottom, even if it does go outside the world bounds, it does not get killed. Has anyone seen behavior like this? The world is 16000 x 16000. The sprite retracks its target every time update() is called, like so: this.bullets.forEach(function (bullet) {this.game.physics.arcade.accelerateToObject(bullet, this.player, 1000, 1000, 1000);}, this);
  18. Thank you. I think that would work. I actually just solved it using a different methodology by tracking the sprite count using countLiving().
  19. I figured it out, thanks for your help!
  20. Thanks. But I've tried that and it doesn't work, either.