Text box center


(Nate ) #1

Hey guys I have some level buttons, and I want to center the level number on the button. I have it working with single digit numbers, but double and triple digit numbers get all funky.

This is what I am doing and it doesn’t seem to work right:

numb.x = numb.textWidth / 2 - this.width/2;

Is there some kind of center property that I am unaware of?


(Bora Kasap) #2

this.numb.x = this.x + this.width / 2 - this.numb.textWidth / 2;

or…

private var graphicfx:Image;
public function Text()
{
graphic = graphicfx = new Text("Text Here");
graphicfx.centerOrigin()
var button:Button = FP.world.getInstance("button1") as Button;
this.x = button.x + button.width/2;
this.y = button.y + button.height/2;
}

(Nate ) #3

Okay thank you very much! I still am not sure how I had this so confused! Your first suggestion worked wonderfully :smiley: