Set window width and window height in project.xml

Hello,
I am using openFL version 8.9 and HAXE to develop HTML5 games.
I have successfully loaded .swf file into my project.
In my Main.hx, I set width as stage.stageWidth and height as stage.stageHeight.
In project.xml instead of hard coding width and height as:

<window width="800" height="640"/>

, I want to set width and height as stage.stageWidth and stage.stageHeight respectively,something like:

<window width=stage.stageWidth height=stage.stageHeight/>.

How do I achieve this?

Works for html5 only I think:
<window width="0" height="0"/>

so maybe you should do that to keep use of other targets:
<window width="0" height="0" if="html5"/>

Wait… That stageWidth and stageHeight are taken from the XML.

You can’t set the XML to point to those variables because those variables read the XML to know their values. (Not literally, but that’s where the value comes from).

If you want a “always fill the screen” you can set the width and height to zero (as ludo explained above)

If I set width and height as 0 in project.xml the page is not responsive. I cant resize it to fit the screen

How odd. Maybe you are lacking resize="true" ?
I use width and height in zero all the time to make responsive games. You then have to listen to the resize event to change everything accordingly

Edit: I remembered I made a blog post about this https://miltoncandelero.github.io/openfl/2019/03/25/resize-vs-responsive.html

1 Like

If you set 0 in the xml. Your html canvas in your html will be 100%.
But that doesn’t mean that all your openfl content will fit your canvas.
So you need to listen to the resize event.
I think somebody is currently working on SCALE_MODE so maybe you won’t have to do it by yourself soon.

Thanks for post! It worked.

1 Like