qvintusgud

Members
  • Content Count

    21
  • Joined

  • Last visited

  1. qvintusgud

    How do I restart scene?

    Great samme, that works fine! I tried to do the same from a "game over scene". The mission is to restart the previous scene. But If I try to do that it also restart and play the last scene. Is it possible to do that?
  2. qvintusgud

    How do I restart scene?

    Okay, same as me, Do you destroy the scene or something before you restart it?
  3. qvintusgud

    How do I restart scene?

    Hi blackhawx, Thank you very much for your respond, I tried to use your code but I still get an error message "Uncaught TypeError: Cannot read property '_pendingInsertion' of undefined" in UpdateList.js:275, I aslo had a console message within the callback and it still double up each time. With version do you use? Are you using webpack?
  4. 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);
  5. 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
  6. 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(); }); } }
  7. 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
  8. 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?
  9. 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
  10. 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;
  11. 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 ?
  12. 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
  13. 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
  14. 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
  15. 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