Browser resizing and coordinates

Monkey Targets Forums/HTML5/Browser resizing and coordinates

frank(Posted 2013) [#1]
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?


Beaker(Posted 2013) [#2]
Use game.MouseX() etc instead of MouseX(). Discussion here:
http://www.monkeycoder.co.nz/Community/posts.php?topic=2567


frank(Posted 2013) [#3]
Thanks! That will also work for Touch (because TouchX/TouchY go wrong as well).


therevills(Posted 2013) [#4]
Please note, for the latest versions of Diddy please use diddyGame.mouseX instead of game.mouseX.


frank(Posted 2013) [#5]
Unfortunately it's not working; when it uses max-height, the coordinates will be completely off, no matter if I use diddyGame.MouseX.


therevills(Posted 2013) [#6]
Example code?


frank(Posted 2013) [#7]
Will make some small code to reproduce and post it here.


frank(Posted 2013) [#8]
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.


therevills(Posted 2013) [#9]
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.


frank(Posted 2013) [#10]
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?


ziggy(Posted 2013) [#11]
@frank: I think you're missing a Cls in your rendering


frank(Posted 2013) [#12]
@ziggy: sorry? What do you mean?