Hi! I use Backdrop to my “moving” background. Now I want to switch graphic in Backdrop in specific situation (for example pressed Key). Is there any way to to this in simple way or I have to add new Backdrop with new graphic?
[SOLVED] Switching graphic in Backdrop
Ultima2876
(Ultima2876)
#2
You could do it with a graphiclist:
//IN YOUR ENTITY
private var _backdrop1: Backdrop;
private var _backdrop2: Backdrop;
private var _graphicList: Graphiclist;
public override function added(): void
{
super.added();
_backdrop1 = new Backdrop(GFX_BACKDROP_1);
_backdrop2 = new Backdrop(GFX_BACKDROP_2);
_graphicList = new Graphiclist(_backdrop1, _backdrop2);
_backdrop1.visible = true; //backdrop1 is initially visible
_backdrop2.visible = false; //invisible while backdrop1 is visible
graphic = _graphicList;
}
public function switchBackdrop(): void
{
//toggle backdrop display
_backdrop1.visible = !_backdrop1.visible;
_backdrop2.visible = !_backdrop2.visible;
}
Ultima2876
(Ultima2876)
#4
The main advantage to using a Graphiclist in this was is that the backdrops are only allocated once at the beginning rather than a new one each time you change. Thinking about it though, the Graphiclist isn’t actually necessary;
//IN YOUR ENTITY
private var _backdrop1: Backdrop;
private var _backdrop2: Backdrop;
public override function added(): void
{
super.added();
_backdrop1 = new Backdrop(GFX_BACKDROP_1);
_backdrop2 = new Backdrop(GFX_BACKDROP_2);
graphic = _backdrop1;
}
public function switchBackdrop(): void
{
//toggle backdrop display
if(graphic == _backdrop1)
{
graphic = _backdrop2;
}
else graphic = _backdrop1;
}
Calemb
(Bartłomiej Kalemba)
#5
I must use GraphicList because now, I have more than just only one Backdrop. As You wrote, I observe memory and it isn’t increasy during a lot of swiching, so I think I can set as SOLVED