jasper1990 Posted April 23, 2018 Share Posted April 23, 2018 I'm developing a rail shooter and I'm trying to copy the bullet class from phaser 3 example here : https://labs.phaser.io/view.html?src=src\games\defenda\test.js&v=3.2.1. I'm having issues with no bullets appearing *when I press spacebar*, there appears to be no errors in the console either. I'm not entirely sure how groups work, but could someone explain to me? I'm using phaser 3.2.1 railshooter.zip Link to comment Share on other sites More sharing options...
digitsensitive Posted April 25, 2018 Share Posted April 25, 2018 Hello @jasper1990! Can you please post the related code, which you believe is the problem? Link to comment Share on other sites More sharing options...
jasper1990 Posted April 27, 2018 Author Share Posted April 27, 2018 I added a zip file, but specifically I get an issue with the following : function create (){ var Bullet = Phaser.Class({ Extends: Phaser.GameObjects.Image, initialize: function Bullet(scene) { Phaser.GameObjects.Image.call(this, scene, 0, 0, 'bullet'); this.speed = 0; this.born = 0; }, fire: function (argplayer) { this.setPosition(argplayer.x, argplayer.y); this.speed = 20; this.born = 0; }, update: function (time, delta) { this.y += this.speed * delta; this.born += delta; if (this.born > 1000) { this.setActive(false); this.setVisible(false); } } }); player = new Player(this, 100, 400); this.anims.create({ key: 'middle', frames: this.anims.generateFrameNumbers(PLAYER_LABEL, { start: 0, end: 2 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'left', frames: this.anims.generateFrameNumbers(PLAYER_LABEL, { start: 3, end: 5 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'right', frames: this.anims.generateFrameNumbers(PLAYER_LABEL, { start: 6, end: 8 }), frameRate: 10, repeat: -1 }); this.bullets = this.add.group({ classType: Bullet, runChildUpdate: true }); this.lastFired = 0; cursor = this.input.keyboard.createCursorKeys(); KeyZ = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z); KeyX = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.X); KeyC = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.C); } function update (time, delta){ if (cursor.right.isDown) { player.moveRight(); if(player.checkBoundary(256,512, 0)) { player.moveLeft(); } } else if(cursor.left.isDown) { player.moveLeft(); if(player.checkBoundary(256,512, 0)) { player.moveRight(); } } else if(cursor.up.isDown) { player.moveUp(); if(player.checkBoundary(256,512, 0)) { player.moveDown(); } } else if (cursor.down.isDown) { player.moveDown(); if(player.checkBoundary(256,512, 0)) { player.moveUp(); } } if(KeyZ.isDown) { player.aimLeft(); } if(KeyX.isDown) { player.aimMiddle(); } if(KeyC.isDown) { player.aimRight(); } if (cursor.space.isDown && time > this.lastFired) { var bullet = this.bullets.get(); bullet.setActive(true); bullet.setVisible(true); if (bullet) { bullet.fire(player); this.lastFired = time + 100; } } player.renderAim(); } Link to comment Share on other sites More sharing options...
digitsensitive Posted April 28, 2018 Share Posted April 28, 2018 @jasper1990 cant see the problem right now. break down the problem a bit, put some console.log() inside the functions and check whether the code ever gets there. check the console for that. and if there is an error in the console, report it. Link to comment Share on other sites More sharing options...
Recommended Posts