Creating a second game window in HaxeFlixel

525 Views Asked by At

I wanted to add a second window and I even succeeded, but it is empty and I don’t know how to add anything there, I also couldn’t find a normal description of what is responsible for what. I can’t understand what exactly the parameters in "WindowAttributes" are responsible for and how can I load some stage into a new window.

Can I immediately bind some stage to this window and how to do it?

Here's what I did:

override public function create()
    {
        var app = new openfl.display.Application();

        var attributes:lime.ui.WindowAttributes = {
            allowHighDPI: false,
            alwaysOnTop: false,
            borderless: false,
            // display: 0,
            element: null,
            frameRate: 60,
            fullscreen: false,
            height: 300,
            hidden: false,
            maximized: false,
            minimized: false,
            parameters: {},
            resizable: true,
            title: "second window",
            width: 300,
            x: 330,
            y: 300,
        };

        attributes.context = {
            antialiasing: 0,
            background: 0,
            colorDepth: 32,
            depth: true,
            hardware: true,
            stencil: true,
            type: null,
            vsync: true
        };

        app.createWindow(attributes);

        super.create();
    }

I still do not understand what I can enter in the "elements" and "parameters" parameters


Update for 01/10/2023

I found a very stupid solution on how I can add sprites to the second window. We draw our existing sprite using shapes.

var imageCool = new Sprite();

    override public function create()
    {
        var app = Lib.application.createWindow({
            allowHighDPI: false,
            alwaysOnTop: false,
            borderless: false,
            // display: 0,
            element: null,
            frameRate: 60,
            fullscreen: false,
            height: 500,
            hidden: false,
            maximized: false,
            minimized: false,
            parameters: {},
            resizable: true,
            title: "second window",
            width: 500,
            x: 330,
            y: 300,
        });

        var image = new FlxSprite(0, 0).loadGraphic("assets/images/freeplay.png");
        add(image);

        var rect = new Rectangle(image.x, image.y, image.width, image.height);

        app.stage.color = 0xFF010101;

        imageCool.scrollRect = rect;
        imageCool.x = 0;
        imageCool.y = 100;
        imageCool.graphics.beginBitmapFill(image.pixels);
        imageCool.graphics.drawRect(0, 0, image.pixels.width, image.pixels.height);
        imageCool.graphics.endFill();

        app.stage.addChild(imageCool);

        super.create();
    }
1

There are 1 best solutions below

1
YellowAfterlife On

There are several layers to this, some of which you are probably aware of - OpenFL runs on top of Lime, and HaxeFlixel runs on top of OpenFL.

A Lime window is pretty raw and does approximately nothing unless you tell it to. An OpenFL window contains a Flash-equivalent Stage element that you can add DOM elements to. HaxeFlixel adds its elements to DOM, though it is hard to answer whether it supports multiple windows out of box. But perhaps you can either add an FlxCamera's flashSprite to the new window's DOM or create a new Bitmap to render its BitmapData.

Other than that:

  • You should not be creating a new Application, you can get your current one through openfl.Lib.application
  • The newly created window has a stage field that you should be able to add things to.
  • You can take a look around the OpenFL source code to see how createWindow is used, though the code also suggests that you can define additional windows in application XML configuration.