Safe Posted August 1, 2014 Share Posted August 1, 2014 Hey,I'm actually a beginner in phaser and I try to do a based turn game.I have some problems with listener. I have sprites that have a same type listener and I don't want to do 1 listener for 1 sprite.I saw some topic who use tab and group but i didn't really get it.I actually tried to pass the sprite as the argument of the listener but it seems that it doesn't work. So the goal is to make move an unit. So I did two listener one to select the sprite and an another to make the unit move.So (sorry variable and comments are in french): //Sprite du chiens1 = this.moteur2.add.sprite(0, 250, 'Chien'); //Listener sur le sprite s1s1.inputEnabled = true;s1.events.onInputDown.add(spriteInputListener, this); s2 = this.moteur2.add.sprite(200, 400, 'Chien');s3 = this.moteur2.add.sprite(0, 500, 'Chien'); //Si cette fonction est appelé cela veut dire que//le sprite s1 est selectionnéfunction spriteInputListener() { // Listener sur un clic gauche sur la carte this.moteur2.input.onDown.add(mouvement, this)} function mouvement() { //On place le sprite là où le clic à était fait s1.reset(this.marker.x, this.marker.y); //On coupe les listeners pour stopper la selection this.moteur2.input.onDown.removeAll(); } So I want that s1, s2, s3 have the same listener. Hope you will help me And sorry for my english xD Link to comment Share on other sites More sharing options...
horkoda Posted August 2, 2014 Share Posted August 2, 2014 Rich explains this better than I ever will In your situation this means creating a group, putting all your sprites in the group, and using the following code: group.setAll('inputEnabled', true); group.callAll('events.onInputDown.add', 'events.onInputDown', spriteInputListener, this); Link to comment Share on other sites More sharing options...
Safe Posted August 3, 2014 Author Share Posted August 3, 2014 Thanks ! It work well :3Just a little question before closing this topic, is it normal that in the documentation in Graphics there are not fonction like drawRect() or lineStyle()?Here my code :this.init = function() { moteur = new Phaser.Game(1500, 800, Phaser.CANVAS, this.element.replace("#", ''), { preload: this.preload, create: this.create, update: this.update, render: this.render });};On the create :groupe_unit = moteur.add.group();groupe_unit.create(0, 250, 'Chien', 0);groupe_unit.create(200, 400, 'Chien', 0);groupe_unit.create(0, 500, 'Chien', 0);groupe_unit.setAll('inputEnabled', true);groupe_unit.callAll('events.onInputDown.add', 'events.onInputDown', spriteInputListener);On the listener : (For spriteInputListener you can have the sprite which is calling the listener just by adding a paramater (see the doc))this.mouvement = function() { //On place le sprite là où le clic à était fait moteur.spriteMove.reset(this.marker.x, this.marker.y); //On coupe les listeners pour stopper la selection moteur.input.onDown.removeAll(); }; // Si cette fonction est appelé cela veut dire que le sprite s1 est selectionné function spriteInputListener(sprite) { // Listener sur un clic gauche sur la carte moteur.spriteMove = sprite; moteur.input.onDown.add(systeme.game.mouvement, systeme.game); }; Link to comment Share on other sites More sharing options...
XekeDeath Posted August 3, 2014 Share Posted August 3, 2014 Just a little question before closing this topic, is it normal that in the documentation in Graphics there are not fonction like drawRect() or lineStyle()? Those are not in the Phaser docs because they are not Phaser functions, they are PIXI functions.You will find them in the PIXI docs here: http://www.goodboydigital.com/pixijs/docs/classes/Graphics.html Link to comment Share on other sites More sharing options...
Safe Posted August 3, 2014 Author Share Posted August 3, 2014 Oh ok thanks ! Link to comment Share on other sites More sharing options...
Recommended Posts