Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by stahlmanDesign

It doesn't seem that double-clicking is supported. I looked it up and there seems to be an onDblClick eventListener built into JavaScript, but I wasn't able to get it to work in Impact.

Is there a reason it is not part of Impact? Right now I have the player moving by clicking on the screen, but I want double-click to make him jump.

1 decade ago by stahlmanDesign

I came up with my own double-click detection.

In my entity I have a timer in the init function called
this.doubleClickTimer = new ig.Timer(0.3);

and a boolean variable
checkForDoubleClick: false,

If I let up the mouse, checkForDoubleClick = true.
If I am just holding the mouse down, checkForDoubleClick = false;

Then in the update loop I see if the mouse is down, if I should check for double click, and if it has been 0.3 seconds since I last let up the mouse.

If these conditions are not met, then the timer is reset, because when I let up, the timer keeps running, and if I press down again fast enough, it will meet all the conditions for double click, and will jump.
if (ig.game.pressedState) {
		
		if (checkForDoubleClick && (this.doubleClickTimer.delta() < 0) && this.standing)
		{this.vel.y = -this.jump;}
		else
		{this.doubleClickTimer.reset();}
		checkForDoubleClick=false;
...
else
{this.checkForDoubleClick=true;}
Page 1 of 1
« first « previous next › last »