Drawing Gui on screen


(Roger Burgess) #1

I am currently working on a Gui for my Platformer but what i have jumps around or is slower than the camera movement.

in my Gui update event have this

public function GUI(x:Number=0, y:Number=0) 
    {
     graphic = new Image(Button);		
    }
    override public function update():void 
    {			
    	x = FP.camera.x + FP.screen.width/2;
    	y = FP.camera.y + FP.screen.height/2;
    }

any way for it to move more smoothly?


(Alex Larioza) #2

You’ll want to move the UI entity before the update function within your world class

// MyGameWorld.as
...
override public function update():void 
{			
    myHud.x = camera.x + FP.screen.width/2;
    myHud.y = camera.y + FP.screen.height/2;
    super.update();
}

(Roger Burgess) #3

I’m not quite sure how to do that fairly new to FP.


(Roger Burgess) #4

so far it Didn’t change when to use in the World.as

override public function addGraphic(graphic:Graphic, layer:int = 0, x:int = 0, y:int = 0):Entity 
{
    x = FP.camera.x + FP.screen.width/2;
    y = FP.camera.y + FP.screen.height/2;
	return super.addGraphic(graphic, layer, x, y);
}
override public function update():void 
{
    GUI.xx = FP.camera.x + FP.screen.width/2;
	GUI.yy = FP.camera.y + FP.screen.height/2;
	super.update();
}

(Alex Larioza) #5

Well in your code, you’re setting “xx” and “yy” instead of the x/y variables:

// MyWorld.as
...
override public function update():void 
{
   GUI.x= camera.x + FP.screen.width/2;
   GUI.y= camera.y + FP.screen.height/2;
   super.update();
}

Also, why are you overriding the addGraphic() function? The code you added is just going to set graphics to the center of the screen when first added.


(Roger Burgess) #6

when i set x/y directly it gives errors. the Gui it self is a Separate .as from the level, i thought there might be a method to drawing the Gui to the screen unaffected by the camera following the player.


(Alex Larioza) #7

Wait are you trying to set the x/y statically? Your GUI class extends the Entity class right? You should be creating a new instance of your GUI class:

private var hud:HUD;

public function MyWorld()
{
   hud = new HUD();
}

override public function update():void 
{
   hud.x = camera.x + FP.screen.width * 0.5;
   hud.y = camera.y + FP.screen.height * 0.5;
   super.update();
}

(Roger Burgess) #8

when i tried to make HUD setup what import do i need?


(Zachary Lewis) #9

An easier way to keep the GUI in the same location would be to set relative = false on your GUI’s Graphic.

http://useflashpunk.net/docs/net/flashpunk/Graphic.html#relative


(Roger Burgess) #10

i setup Relative to false and its staying put now Thank you zachwlewis.