rhennigg

Members
  • Content count

    38
  • Joined

  • Last visited

1 Follower

About rhennigg

  • Rank
    Advanced Member

Recent Profile Visitors

528 profile views
  1. weapon send a signal each time the weapon fire ?

    Every time the weapon is fired the signal onFire is sended. You can just use it like: weapon.onFire.add(function(){ //do what you want });
  2. Multiple keyboard listeners?

    Hello guys, I've created an object that extends a Phaser Sprite object and I'm trying to put a keyboard listener on it. I'm doing it through (inside the object): game.input.keyboard.addCallbacks(this,function(key){...}); and this works fine for the first object, but, if I instantiate more objects just the last created object receive the keyboard input (seems like the last created overwrites the listener from the previous one). My objective is make all objects listen to the keyboard input, any tip? Thanks in advance!
  3. Change event priority

    Ok, I have a tilemap as background and putting the click handler on the layer fixed my problem. Thanks!
  4. Change event priority

    Hello! I'm having some troubles trying to change the priority of mouse clicks. First I set: this.input.onDown.add(function(){alert("world");}, this); To catch mouse clicks on my entire game window and this works fine. But sometimes I create sprites and I want them to have different mouse clicks events. For this I use: this.spritetest.events.onInputDown.add(function(){alert("sprite");}, this,100); My goal is to give priority to the sprite event function if clicked on a sprite and fire the "general function" if not. But the "general function" ever fires first! I tried to set the priority parameter as you can see on the second function but this doesn't seem to change anything in my case. Can someone points me how I can fix this? Thanks!
  5. Phaser States Player Animation Problem

    Why not? It's working for me...
  6. Change background.

    Create: this.bk = this.add.tileSprite(0,0,this.game.world.width,this.game.world.height,'bkg2'); Change: this.bk.loadTexture('bkg');
  7. Phaser States Player Animation Problem

    var ProjectName = ProjectName || {}; ProjectName.Game = function() { }; ProjectName.Game.prototype = { preload:function() { this.load.image('enemy2', 'assets/star.png'); this.load.image('enemy1', 'assets/dude.png'); }, create : function(){ this.enemies = this.add.group(); this.enemies.enableBody = true; for (var i = 0; i < 1; i++) { this.s = this.enemies.create(this.world.randomX, this.world.randomY, 'enemy1'); this.s.name = 'enemy1' + this.s; this.s.body.collideWorldBounds = true; this.s.body.bounce.setTo(0.1, 0.1); this.s.animations.add('walk', [0, 1,]); this.s.play('walk', 6, true); this.s.body.velocity.setTo(5 + Math.random() * 40, 5 + Math.random() * 40); } { this.f = this.enemies.create(this.world.randomX, this.world.randomY, 'enemy2'); this.f.name= 'enemy2' + this.f; this.f.body.collideWorldBounds = true; this.f.body.bounce.setTo(0.5, 0.5); this.f.animations.add('walk', [0, 1,]); this.f.play('walk', 6, true); this.f.body.velocity.setTo(150 + Math.random() * 40, 5 + Math.random() * 40); } }, update : function() { this.physics.arcade.overlap(this.f, this.s, this.enemyKill, null, this); }, enemyKill: function(enemy1,enemy2){ enemy1.kill(); } }; This is your code inside the Game.js state from the example above. With some minor changes to make it run.
  8. Phaser States Player Animation Problem

    You need to put your entire code in the state not just a function, ok? (If you have a complex game you can split multiple stages in states if you want but for a small game there is no reason to do that...) Like this is an Index.html file pointing to state Main (Main.js). <html> <head> <title> States </title> <meta charset="utf-8"> <script type="text/javascript" src="js/phaser6.2.min.js"></script> <script type="text/javascript" src="js/Game.js"></script> <link rel="stylesheet" type="text/css" href="css/style.css"> </head> <body> <div align="center"> <div id="pgame"></div> </div> <script type="text/javascript" src="js/Main.js"></script> </body> </html> </script> </body> </html> This is the state Main(Main.js) loading state "Game" and running the state Game (Game.js) (there are other states comented just to show that you can load multiple states here if you want and you can call them later if you need through "ProjectName.game.state.start('State');") var ProjectName = ProjectName || {}; ProjectName.game= new Phaser.Game(800, 600, Phaser.AUTO, "pgame",null,false,false); /* ProjectName.game.state.add('Boot', ProjectName.Boot); ProjectName.game.state.add('Preload', ProjectName.Preload); ProjectName.game.state.add('MainMenu', ProjectName.MainMenu); ProjectName.game.state.add('GameOver', ProjectName.GameOver); ProjectName.game.state.add('Credits', ProjectName.Credits); */ ProjectName.game.state.add('Game', ProjectName.Game); ProjectName.game.state.start('Game'); This is "Game.js", here you can put your game: var ProjectName = ProjectName || {}; ProjectName.Game = function() { }; ProjectName.Game.prototype = { preload:function() { }, create : function() { }, update : function() { } };
  9. Help a beginner

    Are you running a local web server?
  10. Phaser States Player Animation Problem

    Not sure if I understood your question but if not, try to explain again... States are used, normally, to change screens/scenes/actions in your game like: state 1 -> load stuffs state 2 -> show menu state 3 -> run game state 4 -> show credits state 5 -> show game over screen... I made a simple example here (you can inspect the code).
  11. Replace background tileSprite.

    Yep, my bad. I've edited to avoid confusion but declaring it 2 times was really nonsense... Thanks for pointing!
  12. How is this JSON file created?

    maybe Dragonbones? (http://dragonbones.com)
  13. Replace background tileSprite.

    No sure if this is the best aproach but you can do something like (on create): this.bk = this.add.tileSprite(0,0,this.game.world.width,this.game.world.height,'bkg2'); And on update: if(condition to change background) this.bk.loadTexture('bkg');
  14. Group with null body after state restart...

    Sorry for asking again, but I'm really stucked on this problem... as the bug never occurs on the first run... is there not a way to make the game work at the same way after the state is restarted? some tip?
  15. Group with null body after state restart...

    ok, thanks for your answer, but why the game works fine on the first time and doesn't work after the game is restarted? (I've tryed to destroy/kill/clear the platform group on shutdown with no success) I'm not figuring out how I can simply make the game work at the same way after the state is restarted... some tip?