Window resize question

Hello, I’m a new OpenFL user.
I’m very excited to start using this instead of just Java & OpenGL.

I have one problem at the moment, the window size problem that I saw multiple people having problems with.
I googled if there was an answer, but most seem outdated and not working.

I currently have a working example project which shows the OpenFL logo, and I tried to resize the window.

Lib.application.window.resize(250,250);

This works, however the stage itself doesn’t get resized. I want the stage to scale down according to the new window size.
I tried using stage.scaleMode, but none of the options seem to have effect.

What am I doing wrong?

This is my whole code

package;

import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.Assets;
import openfl.Lib;
import openfl.display.Stage;

class Main extends Sprite {

    public function new () {
        Lib.application.window.resize(250,250);
        super ();

        var bitmapData = Assets.getBitmapData ("assets/openfl.png");
        var bitmap = new Bitmap (bitmapData);

        addChild (bitmap);

        bitmap.x = (stage.stageWidth - bitmap.width) / 2;
        bitmap.y = (stage.stageHeight - bitmap.height) / 2;
    }
}

Also, another question if I’m allowed(They just hate you for it if you add a question in another question on StackExchange):
I noticed there are 3D functions, are they ‘developed’ yet? For example, do OpenGL shaders work?
I saw a post from over a year ago they were planning custom OpenGL shaders.

1 Like

As Joshua said in this thread, the legacy version has scaleMode working, but the new version doesn’t yet.

You can enable legacy mode by adding <set name="openfl-legacy" /> to project.xml, or you can try this solution.

okay thanks! I’ll try that :slight_smile:

If you are using Lime 2, you can access the current Window object using:

Lib.application.window

It has a resize method, you also move it or close it :wink:

http://docs.openfl.org/lime/ui/Window.html#resize

Pretty sure that wasn’t the problem…

Oh, I missed (somehow) that you already called this. It should resize the stage, but you need to listen to stage.addEventListener (Event.RESIZE, ...); in order to catch when it changes and update your code accordingly (like re-centering an image)

Is it possible to track browser window resize events in HTML5?
stage.addEventListener(Event.RESIZE, ...) doesn’t work for them.

We don’t dispatch any, currently. The stage resize events occur if the parent DIV for your HTML5 content resizes. If you use percentage based CSS on that DIv then you will get a resize on the window, otherwise use the js.Browser API in Haxe to attach to the window manually

1 Like