'FlxSpriteGroup is not visible (haxeflixel)

I'm trying to create some sort of "item displayer" in a game to showcase items or act as an icon in the inventory (it will include informations like item tier, item name, exc).

To achieve this, i wanted to create a ItemDisplay class extending FlxSpriteGroup, and put inside it the frame, background and info for the item as Sprites, so that i would be able to work with all as if they were a single Sprite.

So i did just that, but the group isn't showing up when the ItemDisplay object is created and supposedly added to the FlxState.

After some troubleshooting, i discovered that the object exists, but isOnScreen() returns false, and i don't know why.

Here's the code i'm using to create the ItemDisplay object:

        var itd:ItemDisplay = new ItemDisplay(FlxG.width / 2, FlxG.height / 2, test_sword);
        add(itd);

...and here's the ItemDisplay class in all it's glory:

class ItemDisplay extends FlxSpriteGroup
{
    override public function new(posX:Float, posY:Float, itemToShow:Item)
    {
        super();
        x = posX;
        y = posY;

        // create sprites
        var bckgr:FlxSprite = new FlxSprite(x, y);
        var itPng:FlxSprite = new FlxSprite(x, y);
        var itFrm:FlxSprite = new FlxSprite(x, y);

        // load sprites graphics (problem's not here, i checked)
        bckgr.loadGraphic("assets/images/ui/item_framing/ifbg_" + itemToShow.tier + "Tier.png");
        itPng.loadGraphic(itemToShow.pngPath);
        itFrm.loadGraphic("assets/images/ui/item_framing/item_frame.png");

        // add all sprites to group
        this.add(bckgr);
        this.add(itPng);
        this.add(itFrm);
    }
}

(i'm running the code on macos, not HTML5)

If you have any idea why the ItemDisplay is not showing up, please explain it to me, as i'm not that good of a programmer, and i might have missed something. Thank you ^-^



Solution 1:[1]

Nvm, as i thought, it was my stupid error: when creating the sprites in lines 10-12, i set their positions to X and Y, to make them the same as the group positions.

I just found out that the sprites consider the group's x and y as (0, 0), and start calculating their position from there.

So, by setting the sprites' x/y the same as the group's, i was essentially doubling the values, and putting the sprites outside of the screen

lmao sorry for bad english

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aw Man