FlxSpriteUtil and encapsulation ? All objects updated by one of them's constructor

17 views
Skip to first unread message

Nicolas Mansart

unread,
Sep 11, 2015, 8:48:41 AM9/11/15
to HaxeFlixel
Hello,
I'm making a simple class for displaying simple progress bars, consisting of a grey background and a colored foreground bar. Both need to be rounded so I used FlxSpriteUtil.drawRoundRect.

My issue here is : When I declare and put on the scene two progress bars, both are drawn with the parameters of the last one.
Example follows.

class TestState extends FlxState
{

   
override public function create():Void
   
{
       
super.create();
       
FlxG.debugger.visible = true;
       
var _test1:ProgressBar = new ProgressBar(70, 0xFFFFCC00);
        _test1
.setPosition(200, 100);
        add
(_test1);
       
var _test2:ProgressBar = new ProgressBar(20, 0xFF00CCFF);
        _test2
.setPosition(200, 200);
        add
(_test2);
   
}
}
class ProgressBar extends FlxSpriteGroup
{
   
private var _picto:FlxSprite;
   
private var _bgBar:FlxSprite;
   
private var _frontBar:FlxSprite;
   
private var _color:Int = 0xFF0000;
   
private var _progress:Int = 0;
   
   
public function new(progress:Int = 50, color:Int = 0xFF999999)
   
{
       
super();
        _progress
= progress;
        _color
= color;

       
this._bgBar = new FlxSprite();
       
this._frontBar = new FlxSprite();
       
this._bgBar.makeGraphic(200, 40, FlxColor.TRANSPARENT);
       
this._frontBar.makeGraphic(200, 40, FlxColor.TRANSPARENT);
       
FlxSpriteUtil.drawRoundRect(this._bgBar, 0, 0, 200, 40, 15, 15, FlxColor.fromRGB(220, 220, 220));
       
FlxSpriteUtil.drawRoundRect(this._frontBar, 200 - 2 * _progress, 0, 2 * _progress, 40, 15,15, FlxColor.fromInt(_color));
       
this.add(this._bgBar);
       
this.add(this._frontBar);
   
}
}


When _test2 is created, _test1 is redrawn (I also tested with a delay on _test2 creation with the same result). If you have any clue of what's wrong, please tell :)

SruloArt

unread,
Sep 11, 2015, 8:56:10 AM9/11/15
to HaxeFlixel
* Check your .makeGraphic method for "unique" and read what it's for :)

Nicolas Mansart

unread,
Sep 11, 2015, 9:07:07 AM9/11/15
to HaxeFlixel
Well I was ready to blame it all on FlxSpriteUtil since the thing worked when I didn't use it, but it makes sense now.
Thank you x)
Reply all
Reply to author
Forward
0 new messages