lluiscab

Members
  • Content Count

    3
  • Joined

  • Last visited

  1. As @symof said, It's just to keep the scope saved on a copy. I normally use this when I code some class based app in nodejs
  2. Thanks for the help with the overlap checking. I was sure it was just like an "init" function so you call it and then the game knows it has to check that every time, but It's just a standard function that needs to be called when I want to check. Thanks for the help
  3. I've been looking a ton of posts on this forums and also some tutorials but I can't make the collision between the bullets and the enemies work. Any help? var Level1 = function(game) {}; Level1.prototype = { preload: function () { this.optionCount = 1; this.player; this.weapon; this.cursors; this.fireButton; this.enemies; }, create: function () { var self = this; this.stage.disableVisibilityChange = false; game.add.text(20, 20, 'Level 1', { font: "20px Arial", fill: '#ffffff'}) self.weapon = game.add.weapon(30, 'weapon'); self.weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; self.weapon.bulletAngleOffset = 90; self.weapon.bulletSpeed = 400; self.weapon.fireRate = 200; self.weapon.fireAngle = Phaser.ANGLE_RIGHT; self.player = this.add.sprite(50, 300, 'user'); self.player.angle = 90; self.player.alpha = 0; game.add.tween(self.player).to({ alpha: 1 }, 1300, Phaser.Easing.Linear.None, true); self.game.physics.arcade.enable(self.player); self.weapon.trackSprite(self.player, 0, 14); self.cursors = this.input.keyboard.createCursorKeys(); self.fireButton = this.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR); self.enemies = game.add.group(); self.enemies.enableBody = true; self.enemies.physicsBodyType = Phaser.Physics.ARCADE; self.enemies.createMultiple(2, 'enemy1'); self.enemies.setAll('anchor.x', 0.5); self.enemies.setAll('anchor.y', 0.5); self.enemies.setAll('scale.x', 0.5); self.enemies.setAll('scale.y', 0.5); self.enemies.setAll('alpha', 0) self.enemies.setAll('outOfBoundsKill', true); self.enemies.setAll('checkWorldBounds', true); var enemy1 = self.enemies.getFirstExists(false); if (enemy1) { enemy1.reset(700, 150); game.add.tween(enemy1).to({ alpha: 1 }, 1300, Phaser.Easing.Linear.None, true); } var enemy2 = self.enemies.getFirstExists(false); if (enemy2) { enemy2.reset(700, 450); game.add.tween(enemy2).to({ alpha: 1 }, 1300, Phaser.Easing.Linear.None, true); } game.physics.arcade.overlap(self.weapon.bullets, self.enemies, self.hitEnemy, null, this); }, update: function() { var self = this; if (self.fireButton.isDown){ self.weapon.fire(); } self.player.body.velocity.y = 0; if (self.cursors.up.isDown) { self.player.body.velocity.y = -200 } else if (self.cursors.down.isDown) { self.player.body.velocity.y = 200; } // Stop at screen edges if (self.player.y > game.height - 50) { self.player.y = game.height - 50; self.player.body.acceleration.y = 0; } if (self.player.y < 50) { self.player.y = 50; self.player.body.acceleration.y = 0; } }, hitEnemy: function(enemy, bullet) { console.log('hey'); } };