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 dmen

I have a game that uses the mouse to position an entity. Works great until I center the div containing the canvas element. Once I do that the left side of the canvas is unresponsive to the mouse - pretty much by the amount the canvas was shifted right to center it...
I can't be the only one to have come across this, so hoping there's a simple fix.

1 decade ago by dominic

How do you center the Canvas element? It's surprisingly difficult to get the mouse position inside of an element and Impact ignores padding and border on it.

The easiest solution is to put the Canvas inside a DIV and center that DIV instead of the Canvas itself.

1 decade ago by dmen

Hey Dominic, thanks for the reply. The canvas is in a div, and I was centering using margin auto... I fixed it by adding a position:absolute to the game div and now it works... Not sure if that makes sense or not, I am not good at CSS.

1 decade ago by dmen

Didn't actually work... it's fine in Chrome but in IE the mouse offset still exists.
Page 1 of 1
« first « previous next › last »