FlxBar not appearing in FlxSpriteGroup

75 views
Skip to first unread message

JustGabe

unread,
Mar 7, 2016, 2:12:57 PM3/7/16
to HaxeFlixel
I dunno what could be the problem, here's the whole code:

package;

import flixel.group.FlxSpriteGroup;
import flixel.text.FlxText;
import flixel.ui.FlxBar;

class HUD extends FlxSpriteGroup
{
private var healthDisplay:FlxText;
private var levelDisplay:FlxText;
private var expBar:FlxBar;
private var HP:Int;
private var maxHP:Int;
private var exp:Int;
private var maxExp:Int;
private var level:Int;

public function new() 
{
super();
scrollFactor.x = 0;
scrollFactor.y = 0;
healthDisplay = new FlxText(2, 2);
HP = 5;
maxHP = 10;
add(healthDisplay);
levelDisplay = new FlxText(2, 12);
level = 1;
add(levelDisplay);
exp = 3;
maxExp = 10;
expBar = new FlxBar(4, 25, FlxBarFillDirection.LEFT_TO_RIGHT, 100, 4, exp, "", 0, maxExp);
expBar.createFilledBar(0xFF63460C, 0xFFE6AA2F);
add(expBar);
}
override public function update(elapsed:Float):Void
{
super.update(elapsed);
healthDisplay.text = "Health: " + HP + "/" + maxHP;
levelDisplay.text = "Level: " + level;
expBar.value = exp;
}
public function addHealth(num:Int):Void
{
HP += num;
if (HP > maxHP)
HP = maxHP;
}
}

and the end result (no FlxBar to be seen):


Gama11

unread,
Mar 7, 2016, 3:41:30 PM3/7/16
to HaxeFlixel
The FlxBar constructor call should look like this:

expBar = new FlxBar(4, 25, FlxBarFillDirection.LEFT_TO_RIGHT, 100, 4, this, "exp", 0, maxExp);

JustGabe

unread,
Mar 7, 2016, 11:52:20 PM3/7/16
to haxef...@googlegroups.com
Still not showing for some reason :/
However, if I write it directly in the PlayState it does appear, but I want it to be shown as part of the HUD class.

JustGabe

unread,
Mar 9, 2016, 1:00:03 PM3/9/16
to HaxeFlixel
Another weird thing happens: no FlxSprite appears if they're added :/

package;

import flixel.FlxSprite;
import flixel.group.FlxSpriteGroup;
import flixel.util.FlxColor;

class GUI extends FlxSpriteGroup
{
private var square:FlxSprite;

public function new() 
{
super();
square = new FlxSprite(10, 10);
square.makeGraphic(30, 30, FlxColor.BLUE);
add(square);
}
}
and in the main class the variable is correctly written:
private var statusGUI:GUI = new GUI();

(in create): add(statusGUI);
and they're the last item added... but if I add text in that class it does show.


Reply all
Reply to author
Forward
0 new messages