• Content count

  • Joined

  • Last visited

About hcakar

  • Rank
  • Birthday 09/02/1992

Profile Information

  • Gender
  • Location
  • Interests
    Phaser, HTML5, CSS3, Javascript, AS3, JQuery,
  1. Phaser game problem

    Hello edvinsdainis, Can you please try this one? 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.eggs = game.add.group(); this.eggs.enableBody = true; } //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; } var _this = this; //Egg spawning if (this.fallenCount < 200) { setTimeout(function () { //Here we use _this for referancing the current state. //It's cause if u just console.log(this); inside this "function" you will see that this isn't reffering our state. //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 will kill all egg's on egg group // this.egg.kill(); //I believe you should use something like this: this.egg.getChildAt(this.fallenCount - 1).kill(); //or .destroy(); this.score += 1; this.scoreTxt.text = this.scoreString + this.score } } I believe the problem is that you cannot use this.egg.kill(); that function possibly should kill one of the egg group's child.
  2. Hello again svatem1 You might wanna check this link: https://phaser.io/news/2016/07/multitexturing-support-added, Hope it will help
  3. As far as i understand that u want to change all texture's on one place. If this is the case, you can create an array and push all elements that u want to track, when u want to change those simply use forEach function and load textures on them. var trackImages = []; a = game.add.sprite(0, 0, 'image'); trackImages.push(a); b = game.add.sprite(0, 0, 'image'); trackImages.push(b); //when u want to change them.. trackImages.forEach(function(val) { val.loadTexture('newImage'); }); One other choice is that you can check here : https://phaser.io/examples/v2/particles/particle-class I know its not about sprite's but you can simply extend Phaser.Sprite class to your custom class and update them all at once. I didn't try this out but it should work.
  4. Phaser game problem

    Hello edvinsdainis, the oplayer's answer could be work for you. I also noticed that you are keep creating group's of eggs and keep enabling body's on them. Delete these two line of code on your update and write them to the create method after creating your cat. That would be more appropriate. This is only a friendly suggestion.
  5. fullScreenScaleMode on IOS

    Hello Everyone, I'm currently using Phaser and first of all Thanks for all developers for Phaser. I've got a problem and wanna share with you guys. I wrote a game and using ScaleManager for full screen. var playScreen = function(game){}; playScreen.prototype = { init: function(){ game.scale.pageAlignHorizontally = true; game.scale.pageAlignVertically = true; game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; game.state.start('TitleScreen'); }, create: function(){ game.add.image(1830, 16, 'fullScreenExit'); this.fullScreenButton = game.add.button(1830, 16, 'fullScreen', changeFullScreen, this); } } function changeFullScreen(){ if(game.scale.isFullScreen == false){ this.fullScreenButton.alpha = 0; game.scale.startFullScreen(false); } else { game.scale.stopFullScreen(); this.fullScreenButton.alpha = 1; } } This works fine on desktop and android but however on IOS it's not working. Please let me know if you have any advance. Thanks.