Adding GUI elements always in front of everything else

  • Hi,

    is there a way to define GUI FlxSprites and FlxText (in a way that they're always in front of everything else we add to the stage)?

  • I would create a new camera for the GUI.

    var guiCam = new FlxCamera();

    Then set the cameras array of every GUI element to guiCam:

    sprite.cameras = [guiCam];
    text.cameras = [guiCam];

    Note: You have to set the cameras of each element not the whole group like this:

    // don't do this
    group.cameras = [guiCam];

  • Oh, I see. Thank you very much @DleanJeans ! Is that the process you usually do for your GUIs? :)

  • I did that because my game had zooming. If your game doesn't, you can simply have 2 groups, 1 for game objects, 1 for the GUI:

    var gameObjects = new FlxGroup();
    var guis = new FlxGroup();

    You may need to set the scrollFactor if your game has scrolling:


    So your GUI will stay still

  • Ok, thank you @DleanJeans !

  • The way I do my GUI stuff is point it at a far distance from the real game where I know I'm never gonna go (say, -5000, -5000) and put all my GUI elements there

    This way I don't have to set cameras for each object individually.

Log in to reply