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 Joncom

I have a couple HTML elements (a textfield and an input) which I plan to use for a chat system and other game command input. The problem is if I set the focus to my text input when the following expression is true:
ig.input.state('chat')

...then Impact seems to think that the very key is never then UN-pressed, until I click back on the canvas, and press and release enter once again (but then of course it does the same thing again).

Is this a known issue? Is there any way to get around it?

1 decade ago by Joncom

Turned out to be an easy fix. Instead of using .state(), I now use .pressed().

There is a new issue now though. Impactjs does not seem to be able to register when I hit enter after typing in some text.

1 decade ago by Joncom

Solved with the following code in the init function of main.js:
// set up chat functionality
		$('#'+this.inputFieldId).bind('keypress', function(e) {
			var code = (e.keyCode ? e.keyCode : e.which);
			if(code == 13) { //Enter keycode
				ig.game.chatInputOff(ig.game);
				$('#canvas').focus();
			}
		});

Hitting enter now clears and hides the text input. However, my player can't walk after that... Even though I used $('#canvas').focus(), the it doesn't seem to be the focus, because I can't walk until I click the canvas once with my mouse. Any ideas?

[edit]

I should mention it works perfect in Firefox. Just in Chrome I have to click on the canvas to get it to work again.
Page 1 of 1
« first « previous next › last »