HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.99k stars 439 forks source link

Question: Method to Bridge OpenFL Objects and Flixel Objects #2720

Closed jonfreynik closed 1 year ago

jonfreynik commented 1 year ago

You all are doing a brilliant job and wonderful work. This is not an issue, but is more of a question. I've been playing around with HaxeFlixel with great success and have started to play around with Feathers UI and other OpenFL libraries and am trying to figure out how to combine them into 1 project.

I was curious if there was an official way to work between them. Like a FlixelOpenFLSprite bridge or something as there does not appear to be a way to add native OpenFL objects into Flixel Sprites or vice versa. Additionally, there does not appear to be a way to access the OpenFL graphics pipeline from HaxeFlixel, I've used the drawing options available in the FlxSpriteUtil Class to draw simple GUI elements but have read that they are more for debugging onscreen elements.

Thank you all for what you've created. I hope to someday soon give back to this awesome community.

Geokureli commented 1 year ago

check out FlxAnimate. @Cheemsandfriends should be able to give more info.

I'm of the opinion that if you want the full benefit of the openfl framework in HaxeFlixel you should just use openfl without HaxeFlixel, especially if you're doing it for UI work. typically FlxAnimate is used for FNF mods that want game logic in HaxeFlixel but with a couple complex vector characters animated in Adobe Animate, without needing gigantic spritesheets

Cheemsandfriends commented 1 year ago

I was curious if there was an official way to work between them.

I was trying to do this, I was doing some shady code that would be basically caching the sprite as a bitmap and then pass that bitmapdata into the camera drawing pixels, at least with displayobjects, but other than that, I would say that stick between the two of them and pretty much it

also, thanks @Geokureli for the shoutout, but I dont think they were thinking on sprite stuff like that tbh, I think they were thinking of like, literally some sort of FlxFlSprite to put it in a way

UncertainProd commented 1 year ago

One way of adding openfl's DisplayObjects into flixel would be to use FlxG.addChildBelowMouse. However, it looks like that would put the openfl sprite on top of everything drawn by flixel no matter when you add the openfl sprite. Example:

class PlayState extends FlxState
{
    var oflshape:Shape; // openfl.display.Shape
    var flixelsprite:FlxSprite;

    override public function create()
    {
        super.create();
        oflshape = new Shape();
        oflshape.graphics.lineStyle(5, 0xffffffff);
        oflshape.graphics.drawCircle(100, 100, 20);
        FlxG.addChildBelowMouse(oflshape);

                flixelsprite = new FlxSprite(100, 100).makeGraphic(60, 30, FlxColor.RED);
                add(flixelsprite);
    }
}
jonfreynik commented 1 year ago

Thank you all for the feedback! That helps me a lot, I will close this question.