espace Posted August 21, 2016 Share Posted August 21, 2016 Hi, I'm searching to detect a long press and next do some stuff. i have seen that there is possible with "hold" but i can't do this. I began below a jsfiddle with inputDown with a circle and it works. Could you help me to do the same but with the notion of long press and delay ? It could be fine https://jsfiddle.net/espace3d/x9gevqsg/ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { create: create, update: update, render: render }); function create() { //when i click on the graphics after a certain delay do some stuff var graphics = game.add.graphics(0, 0); graphics.beginFill(0xFF0000, 1); graphics.drawCircle(300, 300, 100); graphics.inputEnabled = true; graphics.events.onInputDown.add(onHold,this); //when i click on the graphics after a certain delay do some stuff function onHold(graphics, pointer) { console.log("okay") } } function update() { } function render() { } Link to comment Share on other sites More sharing options...
tips4design Posted August 21, 2016 Share Posted August 21, 2016 See this thread: Link to comment Share on other sites More sharing options...
espace Posted August 21, 2016 Author Share Posted August 21, 2016 thanks tips4desing but i want that my function do some stuff after a certain delay. and the update function don't works for me because i have a tween back. Link to comment Share on other sites More sharing options...
espace Posted August 21, 2016 Author Share Posted August 21, 2016 an approach is to compare the event.time on begin - event.time at the end and if this delay is greater than my delay variable then do some stuff...but i don't understand this notion in the documentation .... Link to comment Share on other sites More sharing options...
espace Posted August 21, 2016 Author Share Posted August 21, 2016 anybody ? Link to comment Share on other sites More sharing options...
symof Posted August 22, 2016 Share Posted August 22, 2016 This is my approach, but there might be a simpler solution. https://jsfiddle.net/x9gevqsg/1/ Just ask if you don't understand how it works, but it fairly straight forward, and it should work with anything. Link to comment Share on other sites More sharing options...
Ralph Posted August 22, 2016 Share Posted August 22, 2016 Whenever someone clicks a button, add a phaser timer event for however long you want the delay to be, whenever the function from the delay is called, check if the button they are pressing is still being held down, if it is, you know they are long pressing it. If you need to make sure that its the same hold and they havent just pressed the button numerous times, setup a counter for how many times the button has been pressed, pass that into the function, if the number passed into the function is different than the current counter then they have pressed the button more times and do not do the action after the delay. Link to comment Share on other sites More sharing options...
espace Posted August 22, 2016 Author Share Posted August 22, 2016 Hi Symof and Ralph, thanks both. I began an another jsfiddle yesterday night, it's the same approach. I use the pointer.duration to know the time function getTime(pointer) { var lastDuration = pointer.duration; console.log(lastDuration) } Ralph 1 Link to comment Share on other sites More sharing options...
espace Posted August 22, 2016 Author Share Posted August 22, 2016 this is my approach : https://jsfiddle.net/espace3d/woteaqvh/ P.S : just if you know how to do a transition scale at the center with a graphic object because anchor and pivot doesn't work ? Link to comment Share on other sites More sharing options...
espace Posted August 22, 2016 Author Share Posted August 22, 2016 with sprite https://jsfiddle.net/espace3d/2gy8m81u/ Link to comment Share on other sites More sharing options...
Recommended Posts