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 Aitor

I want to detect when the mouse wheel scrolls up or down. I have tried binding ig.KEY.MWHEEL_UP and ig.KEY.MWHEEL_DOWN to 'up' and 'down' actions, but
both ig.input.state and ig.input.pressed return always false when I try to check If the mouse wheel has scrolled. How can I do this?
Thanks in advance

1 decade ago by dominic

That's exactly how it should work.

Did you try binding other keys? Does it only fail with the mouse wheel, or for all keys? Show us some code! :)

1 decade ago by Aitor

Thanks for the answer!
This is de code I use to bind the mouse wheel:
ig.input.bind(ig.KEY.MWHEEL_UP,'selectionNext');
ig.input.bind(ig.KEY.MWHEEL_DOWN,'selectionPrevious');

And this is the code that checks if the mouse has scrolled:
if (ig.input.state('selectionNext'))
{
   this.selectedIndex++;
   if (this.selectedIndex>4)
   {
      this.selectedIndex=4;
   }
}
if (ig.input.state('selectionPrevious'))
{
   this.selectedIndex--;
   if (this.selectedIndex<0)
   {
      this.selectedIndex=0;
   }
}

If I bind ig.KEY.RIGHT_ARROW and ig.KEY.LEFT_ARROW (for example) to the actions instead of the mouse wheel it works perfectly, so I think it only fails with the mouse wheel

1 decade ago by dominic

This should definitely work.

Do you maybe have some sort of addon installed that changes the behavior of the mouse wheel? Which browser/os are you using?

1 decade ago by Aitor

I'm using Windows 7 and Mozzila firefox (I'm now downloading crhome to try the game on it). And I don't have anything that changes the behavior of the mouse wheel, at least I don't remember installing anything like that.

1 decade ago by dominic

Upload your game somewhere so we can have a look.

1 decade ago by Aitor

Maybe the problem is in my computer. I've tried modifying the pong source code adding only this in the game's init function:
ig.input.bind( ig.KEY.MWHEEL_UP, 'wheelUP');

and this on the game's update function:
if (ig.input.state('wheelUP'))
{
	alert("Wheel up");
}

and It still doesn't work. I'll upload the modified pong game (I am finishing the game and I still don't want to upload it), and see if it only fails for me. I've also tried on chrome and It still doesn't work.
EDIT: I can upload the modified pong game, right? I mean, if I upload it baked, is there any problem?

1 decade ago by dominic

Oh, damn. I just tried it with the Pong example aaaaand - it didn&039;t work. I suddenly remembered that I recently fixed the #input.js to correctly handle the mouse wheel.

The fixed version is in git repo already.

Or, you can fix it by hand: in input.js replace
window.addEventListener('mousewheel', this.mousewheel.bind(this), false );

(around line 119) with:
var mouseWheelBound = this.mousewheel.bind(this);
ig.system.canvas.addEventListener('mousewheel', mouseWheelBound, false );
ig.system.canvas.addEventListener('DOMMouseScroll', mouseWheelBound, false );

and the mousewheel method with:
mousewheel: function( event ) {
	var delta = event.wheelDelta ? event.wheelDelta : (event.detail * -1);
	var code = delta > 0 ? ig.KEY.MWHEEL_UP : ig.KEY.MWHEEL_DOWN;
	var action = this.bindings[code];
	if( action ) {
		this.actions[action] = true;
		this.presses[action] = true;
		this.delayedKeyup[action] = true;
		event.stopPropagation();
		event.preventDefault();
	}
}

I'm so sorry for this :/

1 decade ago by Aitor

Nevermind, thanks for solving the answer!
Page 1 of 1
« first « previous next › last »