erikwittern Posted April 24, 2014 Share Posted April 24, 2014 Hi there, I would like to react to the player holding down the input on a sprite (e.g., called obj, with inputEnabled = true). On a desktop, I can achieve this for the mouse using:if(obj.input.pointerDown()){ // do something...}On mobile, however, the code does not work - I believe I would have to use something like pointer1, but it seems only to be accessible for the game object, for example:game.input.pointer1.isDownIs there a way to activate/use pointer1 on sprites as well? Link to comment Share on other sites More sharing options...
Heppell08 Posted April 24, 2014 Share Posted April 24, 2014 You can have it set as this.input.pointer1.isdownAs long as you've assigned all the proper code for the input on the sprite ie: inputEnabled then I don't see why it shouldn't work. Maybe back up the code with a pointer1.isUp so it releases but that is pure speculation since. But in general it should work. I had a game made with draggable sprites and it wasn't too complex. Link to comment Share on other sites More sharing options...
erikwittern Posted April 24, 2014 Author Share Posted April 24, 2014 Hm, you mean obj.input.pointer1.isDown ? Because that does not work, because pointer1 is undefined on obj.input (FYI: obj.inputEnabled = true is set)... Link to comment Share on other sites More sharing options...
erikwittern Posted April 24, 2014 Author Share Posted April 24, 2014 I actually also tried a hack by defining pointer1 as the input of obj like so:obj.input = game.input.pointer1;Interestingly, this works fine. Until you want to change the state in the game - then, it tries to call input.destroy() on pointer1, which does not exist. Any other ideas? Link to comment Share on other sites More sharing options...
erikwittern Posted April 25, 2014 Author Share Posted April 25, 2014 (edited) I think I found my solution: I use the dragging functionality for my purpose (thanks, Heppell08, for hinting at this). So what I do is: I enable dragging with:obj.input.enableDrag();(Note: obj.input.draggable = true; does enable reacting to dragging as well, but produced errors in my case because some instantiations, e.g. of _dragPoint, are not performed - thus rather use enableDrag()).Then, I can check for it (on desktop and mobile) using:if(obj.input.isDragged){ // do something...}Fortunately, obj.input.isDragged is true even if the pointer is just pressed, no matter of whether actual dragging happens, making this approach suitable for my purpose. As I do not actually want to drag something around (just detect the pointer being pressed), I also prohibit horizontal and vertical dragging using:obj.input.setDragLock(false, false); Edited April 25, 2014 by John135 Link to comment Share on other sites More sharing options...
Recommended Posts