I do some compilation from ziggy code and apply to diddy based project (don't test to pure monkey project or other framework yet)
I added new function SetHTMLSize(CanvasWidth, CanvasHeight)
Function SetHTMLSize:Void(_w:Int, _h:Int, _canvasName:String = "GameCanvas")
#If TARGET="html5"
EnableAutoSize()
win.eval("var canvas=document.getElementById( '" + _canvasName + "' );")
'win.eval("CANVAS_WIDTH = "+_w+"; CANVAS_HEIGHT = "+_h+";")
win.eval("canvas.width = "+_w+"; canvas.height = "+_h+";")
win.eval("if( canvas.updateSize ) canvas.updateSize();")
#End
End
It uses ziggy's EnableAutoSize() and win.eval() implementation. Call it in Create method as I show in the example code below. Attention: diddy's SetScreenSize() function has a parametr aspect ration set to True (It is False by default)
Strict
Import diddy
#If TARGET="html5"
Import dom
Extern Private
Global win:windowExtended = "window"
Class windowExtended Extends dom.Window = "Window"
Field innerWidth:Int
Field innerHeight:Int
Method eval:Object(parameter:String) = "eval"
End
Public
#END
Function EnableAutoSize:Void(canvasName:String = "GameCanvas")
#If TARGET="html5"
Local elem:= document.getElementById(canvasName)
If elem <> Null Then
elem.setAttribute("style", "");
EndIf
win.eval("var canvas=document.getElementById( '" + canvasName + "' );canvas.onresize=null;");
win.eval("window.onresize=function (e) {var canvas=document.getElementById( '" + canvasName + "' ); canvas.width = window.innerWidth; canvas.height = window.innerHeight; canvas.style='outline:initial;';} ;")
win.eval("window.onresize()")
#End
End
Function SetHTMLSize:Void(_w:Int, _h:Int, _canvasName:String = "GameCanvas")
#If TARGET="html5"
EnableAutoSize()
win.eval("var canvas=document.getElementById( '" + _canvasName + "' );")
'win.eval("CANVAS_WIDTH = "+_w+"; CANVAS_HEIGHT = "+_h+";")
win.eval("canvas.width = "+_w+"; canvas.height = "+_h+";")
win.eval("if( canvas.updateSize ) canvas.updateSize();")
#End
End
Function Main:Int()
New MyGame()
Return True
End
Class MyGame Extends DiddyApp
Method Create:Void()
SetHTMLSize(480, 800)
SetScreenSize(480, 800, True)
Print DeviceWidth() + " = " + DeviceHeight()
Start(GameScreen.GetInstance())
End
End
|