Search the Community
Showing results for tags 'listener'.
-
So i want to add listener to when the sprite goes out of bounds of the screen. It doesn't seem to fire up. Am I missing something? I saw a post here about this but it uses this.physics.world.on("worldbounds".. but isn't there a way to encapsulate the listener inside a new Sprite child class? Btw is there a list of events i can listen to? Thanks! class Meteor extends Phaser.Physics.Arcade.Sprite{ constructor(scene,x,y,key_texture,frame){ super(scene,x,y,key_texture,frame); this.scene = scene; this.scene.addToWorld(this); this.scene.physics.add.existing(this,false); this.setCollideWorldBounds(true); this.addListener("onOutOfBounds",()=>{console.log("hello")}); } } Ok so apparently if i am setting this.collideWorldBounds(true) it console.logs this.body.onWOrlBounds as true but console.log this has it set to false. If I add a new Meteor(..) from scene.create() method it works fine. If I add it from Spawner class it doesn't.
-
I have this simple game for small children that consists on several images that when tapped should produce a sound. I got it working on the computer (mouse click) but not on mobiles (finger tap) and I suspect that's because I am listening to the wrong event. Could someone tell me how to listen to a image "tap"? My current working code for computers is: // I am adding the functions and listeners dynamically with a // loop so aAssets is an array containing the image elements // enable input window[aAssets[i]].inputEnabled = true; // create the function to be triggered by the listener window['lst'+aAssets[i]] = function (me) { alert (me.key); } // add the respective listener window[aAssets[i]].events.onInputDown.add(window['lst'+aAssets[i]], this); PS: I found the events "onDown" and "onTap" and tried them but both causes an error when added. Thanks!
-
Hi all! My geme have a menu_1 with buttons, if you click some button, then over an old menu_1 creates a new menu_2 with new buttons, but buttons from menu_1 react for click even if it under of new menu_2. I mean, if my button have observable PointerUp and I am creates sprite over this button, then this button react for PointerUp anyway, even under sprite, how I can hide all Observable buttons under one big sprite, that it don't react for pointer, but when I am delete my big sprite, then buttons start react on poiter again? Thank
-
Hi, I'm currently learning Phaser, and i need to handle key events, so i saw some tutorials and if i want to move my character, i need to know if key is down so, in the "phaser" way, things are done like this: window.checkInputs = () => { let key = Phaser.Keyboard if ( game.input.keyboard.isDown(key.LEFT) ) { console.log('Left is down !') } } And i need to call this method in the update loop, so 60 times / s, phaser will check if left arrow is down, like i come from node.js, i don't like this, i mean it waste resources no ? So, is this methode better ? : window.addInput = () => { document.onkeydown = (e) => { if (e.code == 'ArrowLeft') { console.log('Left is down !') } } } Thanks !
-
Is there any way to add a listener that triggers when a sprite is visible by the camera?. The object Sprite contains inCamera, but it seems to re compute the bounds of the sprite according to this: http://www.html5gamedevs.com/topic/8936-does-phaser-handle-object-visibility-according-to-camera/, and that can be expensive. In my case I need to do this for many sprites on the screen, so I want to know if there is a more efficient way to do it.
-
Greetings, I was looking the forum for an answer, but wasn't able to find even the issue. Maybe it's just my wrong usage of Phaser mechanics. Anyway, I'll be gratefull for any information. The matter: I got two separate files ("game.js" and "player.js"). While game.js used as a "state", player.js is just an attached library with some functions. There is hotkey binding in player.js, which is called in game.js within "update" property. You know, to make an object move around. But when the hotkey is pressed, there are from 60 to 150 identical assignments happens. It is about 100 times more on the average than is needed. Question: Is there a solution to make just one assignment? Additional information: I'll try to explain the whole structure in few words. In "game.js" there is variable with object ePow = { x: 100*(settable int), y: 100*(settable int), currentX: 0, currentY: 0 } It is called within "creaton" property of game.js from player.js's another prototype, but I think it isn't important. In "player.js" there is prototype "keybind", which contains creation of hotkeys, listeners for hotkeys and assignment functions. Points of interest within keybind: 1. this.(game.js's context with sprite object).velocity.x = (game.js's context).ePow.currentX; 2. function thrustLeft () { (game.js's context).ePow.currentX = (game.js's context).ePow.x * -1; 3. this.(hotkey).onDown.addOnce(thrustLeft); When hotkeys is pressed console shows me, that value was assignet for 127 times, for example. Help
-
//Create all of our creatures for (var i = 0; i < 30; i++){ creature.events.onInputDown.add(this.listenerClick, this); console.log(i); } // Essential i want to take var i from above and bring it to the function below. How do i do this? listenerClick: function (sprite, pointer) { console.log(sprite); creature[sprite].scale.set(0.0); },
-
Hi, I try to search everywhere and I only found one example which is in ReactPIXI. My question is how I can make React communicate/emit data to PixiJs ? For example, React emit data and it listened by Pixi. Is there any good example out there? Thank you.
-
Yesterday I used onComplete to call a function after an animation finished playing. Today I ran the game and this error: Error: Phaser.Signal: listener is a required param of add() and should be a Function.The function still gets called and does its thing, but the game just stops because of the error. This didn't happen yesterday. The odd thing is that I do have a listener as parameter, and it is a function. My code: wait_for_animation: function(name,framerate) { playerState = 0; player.body.velocity.x = 0; player.animations.play(name, framerate, false); player.animations.currentAnim.onComplete.add(this.change_state(1), this); }, change_state: function(x) { //console.log("it works"); playerState = x; },The "wait_for_animation" function is being called once, not multiple times. What this stuff does is stops the player and plays a character animation. When the animation is done, the player can move again. When I comment out the line that adds the listener, the error doesn't come up.
-
I want documentation on the listener
-
I have a listener on the space button the pause the game, like so: this.space = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);this.space.onDown.add(function() { game.paused = !game.paused;}, this);I press the spacebar once, it pauses the game. I press it again, it unpauses it. I press it AGAIN and it doesn't pause. Why is this happening? Also; if I replace the game.paused = !game.paused;with just console.log("Here.");I get a log at every press, like desired. So it has something to do with the pause mid-execution of the listener. Not sure what the fix for that is, though.