Xp bar madness... graphic-wise [SOLVED]


(John Andersson) #1

Hi. I’m trying to make an xp bar, which updates its own scale depending on Hero.xp

package assets.xp_bar { import net.flashpunk.FP; import net.flashpunk.Entity; import net.flashpunk.Graphic; import flash.geom.Rectangle; import net.flashpunk.graphics.Image;

public class XpBar extends Image
{
	[Embed(source="../XpBar.png")] private const XP:Class;
	
	public function XpBar(XP, clipRect:flash.geom.Rectangle=null) 
	{
		super(source, clipRect);

		x = 460;
		y = 980;
		
		layer = 1;
		
		graphic = new Image(XP);
	}
	override public function update():void 
	{
		x = 460 + FP.world.camera.x;
		this.scaleX = Hero.xp;
	}
}

}

But I get errors no matter what I try to do. Should this be an entity? An image? I don’t get it.

If I make it into an entity, there is no “.scaleX”. God damn it!


(Bora Kasap) #2

Orginal graphic property may not be useful for editing, you may need to create another like

private var graphicfx:Image;

then you can assign both when assigning graphics like

this.graphic = this.graphicfx = new Image(XP);

then you’ll able to edit graphicfx like that

graphicfx.scaleX;
graphicfx.scaleY;
graphicfx.scaledWidth;
graphicfx.scaledHeight;

and’ll have much more properties


(John Andersson) #3

Thanks! :slight_smile: It worked