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 matt_nz

Hi, I find this works ok with jquery:

$(document).keypress(function(e)
{
	alert(e);
});
//press space, 32 is alerted.

However, if this is done first:

ig.input.bind( ig.KEY.SPACE, 'shoot' );

then nothing is alerted, jquery loses the ability to detect the key presses that ig binds.

Does anyone know a workaround for this.

Thanks,

Matt.

1 decade ago by Arantor

I'd argue that any time you're setting it up so that you're trying to use the same key for two different things, you're going to have problems...

The code in question is in input.js in the Impact folder; in the keydown function (amongst others) such that it intentionally prevents passing the event back up the chain - but only if it's one already bound to an ig.Input in the first place, it shouldn't be consuming all keyboard events.

Now, there's two options. I don't know what you're actually trying to do, so I don't know which is better for you.

First, when you're expecting jQuery input, unbind the keypress from Impact, with ig.Input.unbind. This has the obvious caveat of breaking Impact's ability to process that event.

Second, whatever code would normally handle the event, have that also call the function that jQuery would call.

1 decade ago by matt_nz

Hi Thanks for the info.

My situation is a strange one related to this post:

http://impactjs.com/forums/help/play-pause-button (last post).

Once I pause the game, I need to take over with jquery to do all the events, and then when the time is right, start the ig game again.

I unbinded the space key, and this works fine, I can bind it again when I start the game, Thanks for this.

I am starting to wonder why I am using canvas at all though. My game is not very graphics intensive, and it seems the more I take elements outside the canvas, the easier to is to manipulate them. However I might make graphics intensive games in the future, and I hear you need canvas to make this run smooth?

1 decade ago by Arantor

It really comes down to what you're doing. It isn't necessarily about 'graphic intensity' but complexity.

Take the example Biolab Disaster (playbiolab.com) - doing that in HTML/JavaScript without a canvas is going to be painful and frustrating to write and debug, and be very slow to boot. Having a canvas allows you a space to draw any pixels you like in whatever fashion you want, and while it's theoretically doable outside of a canvas, it's beyond frustrating.

I have, I should note, seen it done before - using individual divs to mimic individual pixels on the screen. You can only imagine how slow that's going to get.

On the flip side, a canvas is a single element that you're controlling, not a collection of items in a DOM. It allows you greater control because you're not needing to do all the DOM stuff - but at the same time it does make other things harder.

Something that uses simple drag and drop (like a card game) would probably benefit not being in Impact, but anything that requires any kind of complexity and doesn't map cleanly to divs or imgs is almost certainly better off in Impact.
Page 1 of 1
« first « previous next › last »