Castellvi Posted December 10, 2014 Share Posted December 10, 2014 Hello, I'm trying to trigger a function when a sprite is tapped and holded for 1sec. For the moment, I just capture the x/y position of the pointer on the inputDown of the sprite, and check the position 1sec after that, with a boolean to check if the input has been released. It works fine, but it's a bit buggy, specially when you massively tap the sprite, so I'd like to do it better. I've been trying the onHold function, but unfortunatelly this is not a sprite function but a 'game.input' function, so i'd have to iterate through all of my sprites if I want to check it, and as I have lots of sprites, it doesn't seem to me like the best answer. So I found this 'sprite.downDurration' function, sounds simple and fancy, but I couldn't find out the way to get that working.I've seen this post here, but It didn't help either, here's what I've tried:console.log('Time: ' + sprite.input.downDuration().toFixed(0)); // Returns -1console.log('Time: ' + sprite.input.downDuration(this.game.input.activePointer)); // Crashesconsole.log('Time: ' + sprite.input.downDuration);// Returs " function (a){return a=all0, this._pointerData[a].isDown?this.game.time.time-this.pointerData[a].timeDown:-1;}What am I missing? I've been searching in Phaser Examples but there isn't any example regarding holding an input or something like that. Link to comment Share on other sites More sharing options...
Castellvi Posted December 10, 2014 Author Share Posted December 10, 2014 Ok I realized that downDuration returns -1 if the input is still down so it doesn't work for me either, guess I'll have to find another way, maybe I'll create my own downDuration event. Link to comment Share on other sites More sharing options...
gsko Posted December 10, 2014 Share Posted December 10, 2014 Did you put the sprite.input.downDuration() in your update function? I am currently using this and it works for me. var down = false;function update() { if (down == false && sprite.input.downDuration()>=2000) { // Do stuff down = true; }} Link to comment Share on other sites More sharing options...
Castellvi Posted December 11, 2014 Author Share Posted December 11, 2014 Thanks for your answer gsko.I solved it using the onHold event of the game.input, and then iterating through my sprites and checking if the sprite that I'm dragging has moved since the input down. Link to comment Share on other sites More sharing options...
Recommended Posts