Browser resizing and coordinates
Monkey Targets Forums/HTML5/Browser resizing and coordinates
| ||
When I resize my browser, my games lose their correct coordinates. For instance if I have a 1024x768 and resize my browser, buttons are suddenly not clickable anymore at the location they were first located. I use Diddy and when I zoom the browser (not resize) all is fine. What is the cause of that? Edit: I see my colleague added max-height to the canvas; that seems to be doing it; can I resolve that? |
| ||
Use game.MouseX() etc instead of MouseX(). Discussion here: http://www.monkeycoder.co.nz/Community/posts.php?topic=2567 |
| ||
Thanks! That will also work for Touch (because TouchX/TouchY go wrong as well). |
| ||
Please note, for the latest versions of Diddy please use diddyGame.mouseX instead of game.mouseX. |
| ||
Unfortunately it's not working; when it uses max-height, the coordinates will be completely off, no matter if I use diddyGame.MouseX. |
| ||
Example code? |
| ||
Will make some small code to reproduce and post it here. |
| ||
Here you go; https://gist.github.com/tluyben/5159877 in MonkeyGame.html, in the canvas tag, add style="max-height:100%" put zoom on 100% and open this. The clicking will be right next to the rectangle not inside it. If you zoom out or remove max-height it will be correct. |
| ||
I see... the issue is that you are altering the height/zoom outside of the Monkey code and Monkey/Diddy doesnt know about it. We need a call back system to inform Monkey that the canvas has changed size or something. |
| ||
Yes that is what I thought but I imaged people ran into it before :) Seems something crossplatform needed as well in other targets. Edit: some libs like jungle try to actually accomodate scaling of the window when you resize with zoom +/- ; this doesn't work well either; after that happens controls appear all over the place. Might have something to do with this? |
| ||
@frank: I think you're missing a Cls in your rendering |
| ||
@ziggy: sorry? What do you mean? |