qvintusgud

Members
  • Content Count

    18
  • Joined

  • Last visited

  1. qvintusgud

    How do I restart scene?

    This is my settings.. const config = { type: Phaser.AUTO, width: 420, height: 740, parent : 'gameContainer', physics: { default: 'arcade', arcade: { debug: true } }, scene: [ WelcomeScene, GameScene ] }; const game = new Phaser.Game(config);
  2. qvintusgud

    How do I restart scene?

    the second time I try to restart the scene now I get a console message "Cannot read property '_pendingInsertion' of undefined" from UpdateList.js:275
  3. qvintusgud

    How do I restart scene?

    I have it in the create function, below is some part of the code: class extends PhaserScene constructorsuperkey'GameScene' ; preload } create () { if(buttonGameRestart){ buttonGameRestart.addEventListener('click', (e) => { e.preventDefault(); console.log('restart'); this.scene.restart(); }); } }
  4. qvintusgud

    How do I restart scene?

    If just have a console log in the event listener it only logs once every time, but as soon as I add restart it double up every time
  5. qvintusgud

    How do I restart scene?

    Yes, I just have it once. I installed Phaser with npm v 3.12.0. Can it be cache problems or anything like that?
  6. qvintusgud

    How do I restart scene?

    Hi, I have made a button to restart the scene but some how it looks like it double up the scene instead of just restart. I use thiis if(buttonGameRestart){ buttonGameRestart.addEventListener('click', (e) => { e.preventDefault(); console.log('restart'); this.scene.restart(); }); } And first time I get 'restart' in the console once, next time two times, the 4, 8, 16. 32 etc.. Any idea how I can just reset the scene? First I had a game over scene and a restart button, but I get an console error after a while when the scene start over "Cannot read property 'update' of null" when I used this const gameScene = this.scene.get('GameScene'); gameScene.scene.restart(); maybe someone else had a smilar problem? best regards
  7. qvintusgud

    how can I add physics to Phaser.GameObject.Sprite ?

    Think I get it to work by using the code below, It two types om object, one you should click and one you should avoid. Dont now if its wight way to do it, but I use the code below: let info; let bg; let timedDiamond; let timedEvil; let diamonds; let evils; let testClicks = 0; let canvasHeight; let canvasWidth; class GameScene extends Phaser.Scene { constructor(){ super({ key: 'GameScene' }); } preload () { // load image this.add.image(400, 300, 'sky'); this.load.image('diamond', 'assets/diamant.png'); this.load.image('evil', 'assets/evil.png'); canvasHeight = this.sys.canvas.height; canvasWidth = this.sys.canvas.width; } create () { // groups for objects diamonds = this.physics.add.group({ defaultKey: 'diamond', maxSize: 10, runChildUpdate: true }); evils = this.physics.add.group({ defaultKey: 'evil', maxSize: 10, runChildUpdate: true }); this.input.on('gameobjectdown',this.onObjectClicked); info = this.add.text(0, 300, '', { fill: '#00ff00' }); timedDiamond = this.time.addEvent({ delay: Phaser.Math.FloatBetween(850, 3000), callback: this.addDiamond, callbackScope: this, loop: true }); timedEvil = this.time.addEvent({ delay: Phaser.Math.FloatBetween(1200, 4000), callback: this.addEvil, callbackScope: this, loop: true }); } onObjectClicked(pointer,gameObject){ if(gameObject.texture.key == 'diamond'){ gameObject.setActive(false).setVisible(false); testClicks ++; } if(gameObject.texture.key == 'evil'){ gameObject.setActive(false).setVisible(false); testClicks --; } } addDiamond(){ let diamond = diamonds.get(Phaser.Math.Between(50, (canvasWidth - 50)), 0).setVelocityY(Phaser.Math.Between(300, 600)).setInteractive(); this.activateObject(diamond); } addEvil() { let evil = evils.get(Phaser.Math.Between(50, (canvasWidth - 50)), 0).setVelocityY(Phaser.Math.Between(300, 600)).setInteractive(); this.activateObject(evil); } activateObject(obj){ obj.setActive(true).setVisible(true); } update (time, delta){ Phaser.Actions.IncY(diamonds.getChildren(), 1); diamonds.children.iterate(function (diamond) { if (diamond.y > (canvasHeight + 100)) { diamonds.killAndHide(diamond); } }); info.setText([ 'Points: ' + testClicks, 'Diamonds: ' + diamonds.getTotalUsed(), 'Evils: ' + evils.getTotalUsed() ]); } } export default GameScene;
  8. qvintusgud

    how can I add physics to Phaser.GameObject.Sprite ?

    Oki, but I make more then one, but now I found an other problem. I'm trying to count clicks on the spites. But my counter sometimes give me more then one click. Can't find the problem. So now my code looks like this let info; let bg; let timedEvent; let diamonds; let testClicks = 0; class GameScene extends Phaser.Scene { constructor(){ super({ key: 'GameScene' }); } preload () { bg = this.add.image(400, 300, 'sky'); bg.setInteractive(); this.load.image('diamond', 'assets/diamant.png'); } create () { let Diamond = new Phaser.Class({ Extends: Phaser.Physics.Arcade.Sprite, initialize: function Diamond (scene) { Phaser.Physics.Arcade.Sprite.call(this, scene, 100 ,10, 'diamond'); // scene.physics.world.enable(this); // this.speed = Phaser.Math.GetSpeed(500, 1); console.log(this); }, fire: function(x, y) { this.setPosition(x, y - 50); this.setInteractive(); this.setVelocityY(300); this.setActive(true); this.setVisible(true); this.once('pointerdown', function(){ this.setActive(false); this.setVisible(false); testClicks ++; }); }, update: function(){ if ( this.y > 750 ) { this.setActive(false); this.setVisible(false); } } }); diamonds = this.physics.add.group({ classType: Diamond, maxSize: 100, runChildUpdate: true }); info = this.add.text(0, 300, '', { fill: '#00ff00' }); timedEvent = this.time.addEvent({ delay: 1500, callback: this.onEvent, callbackScope: this, loop: true }); } onEvent(){ let diamond = diamonds.get(); diamond.fire(100, 100); } update (time, delta){ info.setText([ 'Test Clicks ' + testClicks, 'Diamonds' + diamonds.getTotalUsed() ]); } } export default GameScene; sometimes it register 3-4 clicks at once, can't understand how I should fix it. First I had a function that just made new spites but I after a while it start running slow, I think it was because it been to many, Then I made this class so I was able to remove them once they where out of canvas. Should I solve this with some other solution ?
  9. qvintusgud

    trying to count clicks, but it count wrong

    Thanks a lot for your respond Rich, I fixed the setTimeout och now using timedevent. Thats right I would like them to just vanish, but I will make some sort of animation on that when everything is right first. Now it seems to work right, but I dont know if its right way to do it, let info; let bg; let timedDiamond; let timedEvil; let diamonds; let evils; let testClicks = 0; let canvasHeight; let canvasWidth; class GameScene extends Phaser.Scene { constructor(){ super({ key: 'GameScene' }); } preload () { // load image this.add.image(400, 300, 'sky'); this.load.image('diamond', 'assets/diamant.png'); this.load.image('evil', 'assets/evil.png'); canvasHeight = this.sys.canvas.height; canvasWidth = this.sys.canvas.width; } create () { // groups for objects diamonds = this.physics.add.group({ defaultKey: 'diamond', maxSize: 10, runChildUpdate: true }); evils = this.physics.add.group({ defaultKey: 'evil', maxSize: 10, runChildUpdate: true }); this.input.on('gameobjectdown',this.onObjectClicked); info = this.add.text(0, 300, '', { fill: '#00ff00' }); timedDiamond = this.time.addEvent({ delay: Phaser.Math.FloatBetween(850, 3000), callback: this.addDiamond, callbackScope: this, loop: true }); timedEvil = this.time.addEvent({ delay: Phaser.Math.FloatBetween(1200, 4000), callback: this.addEvil, callbackScope: this, loop: true }); } onObjectClicked(pointer,gameObject){ if(gameObject.texture.key == 'diamond'){ gameObject.setActive(false).setVisible(false); testClicks ++; } if(gameObject.texture.key == 'evil'){ gameObject.setActive(false).setVisible(false); testClicks --; } } addDiamond(){ let diamond = diamonds.get(Phaser.Math.Between(50, (canvasWidth - 50)), 0).setVelocityY(Phaser.Math.Between(300, 600)).setInteractive(); this.activateObject(diamond); } addEvil() { let evil = evils.get(Phaser.Math.Between(50, (canvasWidth - 50)), 0).setVelocityY(Phaser.Math.Between(300, 600)).setInteractive(); this.activateObject(evil); } activateObject(obj){ obj.setActive(true).setVisible(true); } update (time, delta){ Phaser.Actions.IncY(diamonds.getChildren(), 1); diamonds.children.iterate(function (diamond) { if (diamond.y > (canvasHeight + 100)) { diamonds.killAndHide(diamond); } }); info.setText([ 'Points: ' + testClicks, 'Diamonds: ' + diamonds.getTotalUsed(), 'Evils: ' + evils.getTotalUsed() ]); } } export default GameScene; best regards
  10. qvintusgud

    trying to count clicks, but it count wrong

    HI Rich, Its just so don't get exactly interval between the sprites. The part I having trouble with is: diamond.on('pointerdown', function(pointer){ testClicks = testClicks + 1; this.setActive(false); this.setVisible(false); }); somethings when I click it count more then one. I'm trying to figure out if I'm binding clicks to the group right or something else I have made wrong
  11. Hi, Im trying to make an infinite loop where I count click on the sprites, But something I get 2-4 counts extra on every click, Tried a couple solutions but I dont get it to work. Anyone have a clue what I'm doing wrong? I use the code below: let info; let bg; let canvasHeight; let canvasWidth; class GameScene extends Phaser.Scene { constructor(){ super({ key: 'GameScene' }); } preload () { bg = this.add.image(400, 300, 'sky'); bg.setInteractive(); this.load.image('diamond', 'assets/diamant.png'); } create () { let Diamond = new Phaser.Class({ Extends: Phaser.Physics.Arcade.Sprite, initialize: function Diamond (scene) { Phaser.Physics.Arcade.Sprite.call(this, scene, 100 ,0, 'ship'); // scene.physics.world.enable(this); this.speed = Phaser.Math.GetSpeed(500, 1); console.log(this); }, fire: function(x, y) { console.log('Spawn new diamond'); this.setPosition(x, y - 50); this.setInteractive(); this.setVelocityY(300); this.setActive(true); this.setVisible(true); }, update: function(){ if (this.y < -50 || this.y > (canvasHeight + 50) ) { this.setActive(false); this.setVisible(false); } } }); diamonds = this.physics.add.group({ classType: Diamond, maxSize: 100, runChildUpdate: true }); info = this.add.text(0, 300, '', { fill: '#00ff00' }); function testSomething() {} (function testloop() { let rand = Math.round(Math.random() * (2000 - 500)) + 500; setTimeout(function() { testSomething(); testloop(); let diamond = diamonds.get(); diamond.fire(100, 100); diamond.on('pointerdown', function(pointer){ testClicks = testClicks + 1; this.setActive(false); this.setVisible(false); }); }, rand); }()); } update (time, delta){ info.setText([ 'Test Clicks ' + testClicks, 'Diamonds' + diamonds.getTotalUsed() ]); } } export default GameScene; best regards
  12. qvintusgud

    how can I add physics to Phaser.GameObject.Sprite ?

    Think I got it right when I changed to extend to Phaser.Physics.Arcade.Sprite instead
  13. Hi, I wonder how I can add physics to my extended class, Tried to change Phaser.GameObject.Sprite to Phaser.Physics.Matter.Sprite but I don't make it to work. I have this code let Evil = new Phaser.Class({ Extends: Phaser.GameObjects.Sprite, initialize: function Evil (scene) { Phaser.GameObjects.Sprite.call(this, scene, 400 ,400, 'ship'); this.speed = Phaser.Math.GetSpeed(500, 1); }, fire: function(x, y) { this.setPosition(x, y - 50); this.setActive(true); this.setVisible(true); }, update: function(time, delta) { this.y += 10; } }); evils = this.add.group({ classType: Evil, maxSize: 100, runChildUpdate: true }); But I would like to have physics and tired to change it, but this dosen't work: let Evil = new Phaser.Class({ Extends: Phaser.Physics.Matter.Sprite, initialize: function Evil (world) { Phaser.Physics.Matter.Sprite.call(this, world, 400 ,400, 'ship'); this.speed = Phaser.Math.GetSpeed(500, 1); }, fire: function(x, y) { this.setPosition(x, y - 50); this.setVelocityY(20); this.setActive(true); this.setVisible(true); }, update: function(time, delta) { } }); evils = this.add.group({ classType: Evil, maxSize: 100, runChildUpdate: true }); How can I make this to work? best regards,
  14. qvintusgud

    Kill spirte if its out of canvas

    Think I solved it Forgot to use fire to make new ones
  15. qvintusgud

    Kill spirte if its out of canvas

    Sweet I tried to modify the code a little bit, But I get some problem when the first object is set to false ( this.setActive(false); this.setVisible(false); ) I cant create new objects anymore, Any ideas why? Here is my new code: let evils; let info; let bg; let canvasHeight; class GameScene extends Phaser.Scene { constructor(){ super({ key: 'GameScene' }); } preload () { bg = this.add.image(400, 300, 'sky'); bg.setInteractive(); this.load.image('ship', 'assets/evil.png'); } create () { canvasHeight = this.sys.canvas.height; let Evil = new Phaser.Class({ Extends: Phaser.GameObjects.Image, initialize: function Evil (scene) { console.log('fire evil'); Phaser.GameObjects.Image.call(this, scene, 400 ,400, 'ship'); this.speed = Phaser.Math.GetSpeed(500, 1); }, fire: function(x, y) { this.setPosition(x, y - 50); this.setActive(true); this.setVisible(true); }, update: function(time, delta) { this.y += .1 * delta; if (this.y < -50 || this.y > (canvasHeight + 50)) { this.setActive(false);this.setVisible(false); } } }); evils = this.add.group({ classType: Evil, maxSize: 300, runChildUpdate: true }); info = this.add.text(0, 300, 'Click to add objects', { fill: '#00ff00' }); bg.on('pointerdown', function(pointer){ let evil = evils.get(); }); } update (time, delta){ info.setText([ 'Used: ' + evils.getTotalUsed(), 'Free: ' + evils.getTotalFree() ]); } } export default GameScene;