rhennig Posted September 28, 2017 Share Posted September 28, 2017 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! Link to comment Share on other sites More sharing options...
samme Posted September 28, 2017 Share Posted September 28, 2017 addCallbacks sets only one callback of each type. If you really need object to listen to any key, create your own Signal, bind all the objects to the Signal, and dispatch the Signal from one of the callbacks. If you don't need to listen to any key, you probably want to use addKey instead. Link to comment Share on other sites More sharing options...
Recommended Posts