Any suggestions on how to do a double click? Just set a timer between clicks? How many milliseconds is the double click on windows?
One other question, is double tapping a phone the same length of time?
Thanks.
Darrin
Any suggestions on how to do a double click? Just set a timer between clicks? How many milliseconds is the double click on windows?
One other question, is double tapping a phone the same length of time?
Thanks.
Darrin
I think you’ll have to use an event listener.It will not be syncronized with the Engine so be a bit carefull about it.
FP.stage.mouseChildren = false;
FP.stage.doubleClickEnabled = true;
FP.stage.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClick);
It will uaw the OS timing for double click, but i don’t know how it works with the tactil screens.
Sure you can use the “isClicked” to try to do something similar, but if you are fast enough you’ll see you han make the game think is a simple click. And there’s also the issue with the timming. With this you don’t have to worry about the time you have to skip, you’ll use the OS one.
PD: As I said above, this will not be called in the update, so i recomend this:
public var doubleClicked:uint = 0;
override public function added():void
{
FP.stage.mouseChildren = false;
FP.stage.doubleClickEnabled = true;
FP.stage.addEventListener(MouseEvent.DOUBLE_CLICK, dbClick);
}
override public function removed():void
{
FP.stage.removeEventListener(MouseEvent.DOUBLE_CLICK, dbClick);
}
override public function update():void
{
while (doubleClicked > 0)
{
doubleClick();
doubleClicked--;
}
}
protected function dbClick(e:Event):void
{
doubleClicked++;
}
public function doubleClick():void
{
//handle here
}
Marty
Thanks. So it works fine. The problem is my code. I have a problem with changing states of the object with a single click before the second click is detected. Currently it works intermittently even though I catch the doubleclick every time.
So I’ve been reading about the cost events. Apparently they are heavy usage. So I have 64 tiles and I don’t think it is best practice to put 64 double event listeners on them. Or is it okay? I couldn’t find any tests.
I then read about something called a callback which could speed things up. Have you used these?
Or I can go to a better single click system, checking state. Still trying to decide. Anyway your code works well. Thank you for that. This seems to be a bigger question about double clicking in games than I was original aware of.
Darrin
Here there are a fews things:
Here i let you a code that i think it may help you
package
{
import flash.events.MouseEvent;
import net.flashpunk.FP;
/**
* ...
* @author Copying
*/
public class DoubleClick
{
public static var clicked:Boolean = false;
public static var x:Number = 0;
public static var y:Number = 0;
public static function event(e:MouseEvent = null)
{
x = FP.camera.x + e.stageX;
y = FP.camera.y + e.stageY;
clicked = true;
}
}
}
Some functions in your world
class
override public function begin():void
{
FP.stage.addEventListener(MouseEvent.DOUBLE_CLICK, DoubleClick.event);
}
override public function end():void
{
FP.stage.removeEventListener(MouseEvent.DOUBLE_CLICK, DoubleClick.event);
}
override public function update()
{
super.update();
//this HAVE to go after super.update() (after the entities check at that frame)
DoubleClick.clicked = false;
}
And in your entities update()
override public function update():void
{
if (DoubleClick.clicked && collidePoint(x, y, DoubleClick.x, DoubleClick.y))
{
//handle here
}
}
basically here you handle it once and then the entities can check if they are double clicked.
So I’m marking this solved even though I decided to go with the single click resolution. I did use your code but thought the other was a bit more elegant for multiple platforms. Thanks again. I will be using this on the next game though. Great stuff. Thanks again.