edvinsdainis

Members
  • Content Count

    8
  • Joined

  • Last visited

About edvinsdainis

  • Rank
    Newbie

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. edvinsdainis

    Help with sprites

    LOL, this fixed the whole thing aquireEgg (cat, egg) { //cat is unnused parameter, but it needs to be here, so egg would be reference to this.egg, othervise it will point to this.cat egg.destroy(); this.score += 1; this.scoreTxt.text = this.scoreString + this.score }
  2. edvinsdainis

    Help with sprites

    Hi guys, for it's deadline to finish this game, and I am stuck with this last bug, the idea is that there is cat catching eggs, and at this point if egg falls to him, it just stands at he's head, and is not being destroyed. Here is the code. import Phaser from 'phaser' //Define all variables to use this(game need's to use global object for chaining). let cat = this.cat; let egg = this.egg; let eggs = this.eggs; let firingTimer = this.firingTimer; let score = this.score; let scoreString = this.scoreString; let scoreTxt = this.scoreTxt let leftMove = this.leftMove let rightMove = this.rightMove export default class extends Phaser.State { preload () { // game.load.atlas('cat-run-move', './assets/animations/cat-run-stand.png', './assets/animations/cat-run-stay.json'); } create() { this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.refresh(); this.physics.startSystem(Phaser.Physics.ARCADE); // this.background = this.add.image(0, 0, "main-bg-deskt"); // this.background.height = this.game.height; // this.background.width = this.game.width; this.leftMove = false; this.rightMove = false; ///123 if (window.innerWidth < 640) { this.background = this.add.image(0, 0, "main-bg-mob"); this.background.height = this.game.height; this.background.width = this.game.width; let soundBtn = game.add.sprite(game.world.centerX+250, game.world.centerY-485, 'sound-on') soundBtn.anchor.setTo(0.5, 0.5); soundBtn.scale.x = 0.8 soundBtn.scale.y = 0.8 //Make cat and anchor it to middle of screen this.cat = game.add.sprite(game.world.centerX, game.world.centerY+500, 'cat-moving') this.cat.anchor.setTo(0.5, 0.5); this.cat.scale.x = 0.5 this.cat.scale.y = 0.5 this.physics.enable(this.cat, Phaser.Physics.ARCADE) this.cat.animations.add('walk', [4,5,9,14], 18, true) // let leftBtn = game.add.button(50, 50, 'ok-soc', null, this) // leftBtn.anchor.setTo(0.5, 0.5) // // leftBtn.events.onInputDown.add(function () { // this.leftMove = true; // }) // // let rightBtn = game.add.button(200, 200, 'ok-soc', null, this) // rightBtn.anchor.setTo(0.5, 0.5) // // rightBtn.events.onInputDown.add(function () { // this.rightMove = true; // }) } if (window.innerWidth > 641) { let soundBtn = game.add.sprite(game.world.centerX+550, game.world.centerY-970, 'sound-on') soundBtn.scale.x = 1.5 soundBtn.scale.y = 1.5 soundBtn.anchor.setTo(0.5, 0.5); //Make cat and anchor it to middle of screen this.cat = game.add.sprite(game.world.centerX, game.world.centerY+500, 'cat-moving') this.cat.anchor.setTo(0.5, 0.5); this.cat.scale.x = 0.5 this.cat.scale.y = 0.5 this.physics.enable(this.cat, Phaser.Physics.ARCADE) this.cat.animations.add('walk', [4,9,14,20], 12, true) } if (window.innerWidth >= 1024) { let soundBtn = game.add.sprite(game.world.centerX+600, game.world.centerY-470, 'sound-on') soundBtn.anchor.setTo(0.5, 0.5); //Make cat and anchor it to middle of screen this.cat = game.add.sprite(game.world.centerX, game.world.centerY+500, 'cat-moving') this.cat.anchor.setTo(0.5, 0.5); this.physics.enable(this.cat, Phaser.Physics.ARCADE) this.cat.animations.add('walk', [4,9,14,20], 12, true) } //Enable physics for cat, set it moving limits inside screen(if physics not enabled for model, you will get body null eror) this.physics.enable(this.cat, Phaser.Physics.ARCADE) this.cat.enableBody = true; this.cat.body.collideWorldBounds = true; //Egg firing timer this.firingTimer = 0; this.eggs = game.add.group(); this.eggs.enableBody = true; this.eggs.createMultiple(100, 'egg') this.eggs.setAll('outOfBoundsKill', true); this.eggs.setAll('checkWorldBounds', true); //Add score counter this.score = 0; this.scoreString = 'Eggs cached: ' this.scoreTxt = game.add.text(10, 10, this.scoreString + this.score, { font: '34px Arial', fill: '#fff' }); } //This method is like watcher for all events in game update () { //Swipe controls for tablets/phones let swipeCoordX; let swipeCoordY; let swipeCoordX2; let swipeCoordY2; let swipeMinDistance = 10; game.input.onDown.add(function(pointer) { swipeCoordX = pointer.clientX; swipeCoordY = pointer.clientY; }, this); game.input.onUp.add(function(pointer) { swipeCoordX2 = pointer.clientX; swipeCoordY2 = pointer.clientY; if(swipeCoordX2 < swipeCoordX - swipeMinDistance){ console.log("left"); this.cat.x -= 5; this.cat.scale.x = 0.5 // this.cat.body.velocity.x = 300 this.cat.animations.play('walk') }else if(swipeCoordX2 > swipeCoordX + swipeMinDistance){ console.log("right"); this.cat.x += 5; this.cat.scale.x = -0.5 // this.cat.body.velocity.x = -300 this.cat.animations.play('walk') }else if(swipeCoordY2 < swipeCoordY - swipeMinDistance){ console.log("up"); }else if(swipeCoordY2 > swipeCoordY + swipeMinDistance){ console.log("down"); } }, this); //Add controls for cat // if (this.leftMove) { // this.cat.x -= 20; // this.cat.scale.x = 0.5 // this.cat.animations.play('walk') // } // // if (this.rightMove) { // this.cat.x += 20; // this.cat.scale.x = -0.5 // this.cat.animations.play('walk') // } this.cat.body.velocity.x=0 if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { this.cat.x -= 10; this.cat.scale.x = 0.5 this.cat.animations.play('walk') } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { this.cat.x += 10; this.cat.scale.x = -0.5 this.cat.animations.play('walk') } else { this.cat.loadTexture('cat-moving', 8) } if (this.game.time.now > this.firingTimer) { this.generateEgg() } this.physics.arcade.collide(this.eggs, this.cat, this.aquireEgg, null, this) // setTimeout(function () { // this.state.start('Result') // }, 20000) } generateEgg () { this.egg = this.eggs.getFirstExists(false); if (this.egg) { this.egg.reset(this.game.world.randomX, 40); this.firingTimer = this.game.time.now + 500; this.egg.body.gravity.y = 1200; this.eggs.add(this.egg) } // this.egg.reset(this.game.world.randomX, 40); // this.firingTimer = this.game.time.now + 350; // this.egg.body.gravity.y = 1200; // this.eggs.add(this.egg) } aquireEgg (egg) { // this.egg.destroy(); // this.egg.body = null; this.eggs.sort('exists') console.log(this.egg) this.egg.destroy(this.eggs.getIndex(this.eggs.getFirstExists(false))) this.score += 1; this.scoreTxt.text = this.scoreString + this.score } }
  3. edvinsdainis

    Phaser game problem

    this.eggs.add(this.egg) I add this to generateEgg and nothing changes, basicly i need, whenewer cat touches falling egg, it should dissapier, and i don't know now where the problem is, any help is needed, thanks
  4. edvinsdainis

    Phaser game problem

    Okay, now first problem is done, here is the code, but now i have second problem, when cat caches egg(its some random icon by now), it is not disappearing, it's just sticking to cat's head and when i move cat, it falls down, and next which is only starting to fall, disappears, the idea is to get that disappears egg which cat collided with. Here is the code: import Phaser from 'phaser' //Define all variables to use this(game need's to use global object for chaining). let cat = this.cat; let egg = this.egg; let eggs = this.eggs; let firingTimer = this.firingTimer; let score = this.score; let scoreString = this.scoreString; let scoreTxt = this.scoreTxt export default class extends Phaser.State { create() { this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.refresh(); this.physics.startSystem(Phaser.Physics.ARCADE); if (window.innerWidth < 640) { let soundBtn = game.add.sprite(game.world.centerX+250, game.world.centerY-485, 'sound-on') soundBtn.anchor.setTo(0.5, 0.5); soundBtn.scale.x = 0.8 soundBtn.scale.y = 0.8 } if (window.innerWidth > 641) { let soundBtn = game.add.sprite(game.world.centerX+550, game.world.centerY-970, 'sound-on') soundBtn.scale.x = 1.5 soundBtn.scale.y = 1.5 soundBtn.anchor.setTo(0.5, 0.5); } if (window.innerWidth >= 1024) { let soundBtn = game.add.sprite(game.world.centerX+600, game.world.centerY-470, 'sound-on') soundBtn.anchor.setTo(0.5, 0.5); } this.background = this.add.image(0, 0, "main-bg-deskt"); this.background.height = this.game.height; this.background.width = this.game.width; //Make cat and anchor it to middle of screen this.cat = game.add.sprite(game.world.centerX, game.world.centerY+500, 'cat-stand') this.cat.anchor.setTo(0.5, 0.5); //Enable physics for cat, set it moving limits inside screen(if physics not enabled for model, you will get body null eror) this.physics.enable(this.cat, Phaser.Physics.ARCADE) this.cat.enableBody = true; this.cat.body.collideWorldBounds = true; //Egg firing timer this.firingTimer = 0; this.eggs = game.add.group(); this.eggs.enableBody = true; this.eggs.createMultiple(100, 'egg') this.eggs.setAll('outOfBoundsKill', true); this.eggs.setAll('checkWorldBounds', true); //Add score counter this.score = 0; this.scoreString = 'Eggs cached: ' this.scoreTxt = game.add.text(10, 10, this.scoreString + this.score, { font: '34px Arial', fill: '#fff' }); } //This method is like watcher for all events in game update () { //Add controls for cat if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { this.cat.x -= 20; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { this.cat.x += 20; } if (this.game.time.now > this.firingTimer) { this.generateEgg() } this.physics.arcade.collide(this.eggs, this.cat, this.aquireEgg, null, this) // if (this.game.time.now) { // this.state.start('Result') // } } generateEgg () { this.egg = this.eggs.getFirstExists(false); if (this.egg) { this.egg.reset(300, 40); this.firingTimer = this.game.time.now + 2000; this.egg.body.gravity.y = 600; } } aquireEgg (egg, cat) { this.egg.destroy(); this.score += 1; this.scoreTxt.text = this.scoreString + this.score } } P.S I tryed with kill and destroy, both same result. This is how it looks.
  5. edvinsdainis

    Phaser game problem

    Thanks for reply, with your code i get error - Uncaught TypeError: Cannot read property 'getChildAt' of undefined
  6. edvinsdainis

    Phaser game problem

    import Phaser from 'phaser' //Define all variables to use this(game need's to use global object for chaining). let cat = this.cat; let egg = this.egg; let eggs = this.eggs; let fallenCount = this.fallenCount; let score = this.score; let scoreString = this.scoreString; let scoreTxt = this.scoreTxt export default class extends Phaser.State { create() { this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.refresh(); this.physics.startSystem(Phaser.Physics.ARCADE); //Refactor this to shorter code, at this time all ifs needed for proper app work on all devices // if (window.innerWidth < 640) { // // } // // if (window.innerWidth > 641) { // // } // // if (window.innerWidth >= 1024) { // // } this.background = this.add.image(0, 0, "main-bg-deskt"); this.background.height = this.game.height; this.background.width = this.game.width; console.log(window.innerHeight) //Make cat and anchor it to middle of screen this.cat = game.add.sprite(game.world.centerX, game.world.centerY+500, 'cat-stand') this.cat.anchor.setTo(0.5, 0.5); //Enable physics for cat, set it moving limits inside screen(if physics not enabled for model, you will get body null eror) this.physics.enable(this.cat, Phaser.Physics.ARCADE) this.cat.enableBody = true; this.cat.body.onCollide(this.removeEgg(), this) this.cat.body.collideWorldBounds = true; //Fallen egg count this.fallenCount = 0; //Add score counter this.score = 0; this.scoreString = 'Eggs cached: ' this.scoreTxt = game.add.text(10, 10, this.scoreString + this.score, { font: '34px Arial', fill: '#fff' }); } //This method is like watcher for all events in game update () { //Add controls for cat if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { this.cat.x -= 20; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { this.cat.x += 20; } //Egg spawning if (this.fallenCount < 200) { setTimeout(function () { this.eggs = game.add.group(); this.eggs.enableBody = true; //Create new eggs and arrange width of drop area this.egg = this.eggs.create(Math.floor((Math.random() * this.game.width) + 1) * 7, 40, 'egg') //Sets speed for egg falling this.egg.body.gravity.y = 200; this.fallenCount +=1 }, 1500) } this.game.physics.arcade.collide(this.egg, this.cat, this.removeEgg, null, this) if (this.fallenCount == 200) { this.state.start('Result') } } removeEgg () { this.egg.kill(); this.score+=1; this.scoreTxt.text = this.scoreString + this.score } } Still not working, now I am getting error in removeEgg method, says, Cannot read property 'kill' of undefined, any help?
  7. edvinsdainis

    Phaser game problem

    thanks guys, i will try this out
  8. edvinsdainis

    Phaser game problem

    Hi, I am developing simple game where eggs are falling from air, and cat will catch them, but i can't get egg caching to work, states changes, cat is moving, and eggs are spawning, but i cant catch them, here is the code. p.s also it says when loading game state, that this.egg is not defined. import Phaser from 'phaser' //Define all variables to use this(game need's to use global object for chaining). let cat = this.cat; let egg = this.egg; let eggs = this.eggs; let fallenCount = this.fallenCount; let score = this.score; let scoreString = this.scoreString; let scoreTxt = this.scoreTxt export default class extends Phaser.State { create() { this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.refresh(); this.physics.startSystem(Phaser.Physics.ARCADE); //Refactor this to shorter code, at this time all ifs needed for proper app work on all devices if (window.innerWidth < 640) { let startBackground = game.add.tileSprite(0, 0, this.game.width, this.game.height, 'start-bg-mob'); startBackground.scale.y = 4.5; startBackground.scale.x = 2.0; } if (window.innerHeight > 700) { let startBackground = game.add.tileSprite(0, 0, this.game.width, this.game.height, 'start-bg-mob'); startBackground.scale.y = 7.7; startBackground.scale.x = 4.0; } if (window.innerWidth > 641) { let startBackground = game.add.tileSprite(0, 0, this.game.width, this.game.height, 'start-bg-tablet') startBackground.scale.y = 2.8; startBackground.scale.x = 2.0; } if (window.innerWidth >= 1024) { let startBackground = game.add.tileSprite(0, 0, this.game.width, this.game.height, 'start-bg') startBackground.scale.y = 1.5; startBackground.scale.x = 2.0; } if (window.innerWidth >= 1367) { let startBackground = game.add.tileSprite(0, 0, this.game.width, this.game.height, 'start-bg') startBackground.scale.y = 1.0; startBackground.scale.x = 2.0; } //Make cat and anchor it to middle of screen this.cat = game.add.sprite(game.world.centerX, game.world.centerY+500, 'cat') this.cat.anchor.setTo(0.5, 0.5); //Enable physics for cat, set it moving limits inside screen(if physics not enabled for model, you will get body null eror) this.physics.enable(this.cat, Phaser.Physics.ARCADE) this.cat.enableBody = true; this.cat.body.collideWorldBounds = true; this.cat.body.onCollide.add(this.removeEgg(), this) //Fallen egg count this.fallenCount = 0; //Add score counter this.score = 0; this.scoreString = 'Eggs cached: ' this.scoreTxt = game.add.text(10, 10, this.scoreString + this.score, { font: '34px Arial', fill: '#fff' }); } //This method is like watcher for all events in game update () { //Add controls for cat if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { this.cat.x -= 20; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { this.cat.x += 20; } //Egg spawning if (this.fallenCount < 200) { setTimeout(function () { this.eggs = game.add.group(); this.eggs.enableBody = true; //Create new eggs and arrange width of drop area this.egg = this.eggs.create(Math.floor((Math.random() * this.game.width) + 1) * 7, 40, 'egg') //Sets speed for egg falling this.egg.body.gravity.y = 200; this.fallenCount +=1 }, 1500) } this.game.physics.arcade.collide(this.egg, this.cat, this.removeEgg(), null, this) if (this.fallenCount == 200) { this.state.start('Result') } } removeEgg () { this.egg.kill(); this.score+=1; this.scoreTxt.text = this.scoreString + this.score } } what should be wrong?