Jump to content

check downDuration of a sprite


Castellvi
 Share

Recommended Posts

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...