Resizing an HTML5 window.

Monkey Forums/Monkey Beginners/Resizing an HTML5 window.

Farflame(Posted 2015) [#1]
I remember this was an issue when I last used Monkey. Can I have my game respond to my window being resized in real-time, i.e if the user resizes the window, can I scale my objects as it happens?

Danilo(Posted 2015) [#2]
Would probably be a good idea to add it to Mojo. There is already OnResize() method in the class 'App', but that's only
for Desktop and Mobiles.
With HTML5, you can modify the template MonkeyGame.html a bit. I did it like this:
function updateSize(){
    //Note! Any resize code that modifies canvas.width/canvas.height/ should call this to update canvas...
    if( canvas.updateSize ) canvas.updateSize();

    // ADDED (last line in updateSize())

But you can probably just add a function call as the last line, so you call a function like OnSizeChanged() at this point.

With Mojo2 OnResize() just works:
Method OnResize:Int()
    canvas.SetProjection2d(0, canvas.Width, 0, canvas.Height)
    canvas.SetViewport(0, 0, canvas.Width, canvas.Height)
    Return 0

- Example