The bullet should be killed after it was shot from the player, and after a certain amount of time.
function create() { bullets = game.add.group(); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; game.physics.enable(bullets, Phaser.Physics.ARCADE); timer = game.time.create(false); for (var i = 0; i < 100; i++) { bullet = bullets.create(0, 0, 'bullet'); bullet.exists = false; bullet.visible = false; bullet.checkWorldBounds = true; bullet.events.onOutOfBounds.add(resetBullet, this); } } function update() { if (game.input.activePointer.isDown) { fire(); } } function fire() { if (game.time.now > bulletTime) { bullet = bullets.getFirstExists(false); if (bullet) { bullet.reset(player.x, player.y); game.physics.arcade.moveToPointer(bullet, 300); bulletTime = game.time.now + 150; timer.add(1000, resetBullet, this); timer.start(); } } } function resetBullet(bullet) { bullet.kill(); } As you can see I already tried adding a timer into the fire function which calls the resetBullet function after one second. But my game crashes one second after fire() was called:
Uncaught TypeError: Cannot read property 'kill' of undefined Does anyone know how to achieve the kill of the sprite?