Text stretching off the screen


(Noah) #1

So I am trying to make dialogue in my game and when the text appears on screen it stretches off the side of the screen. Is there a quick fix for this?

Here’s the code inside my text entity just in case:

package  {
import net.flashpunk.Entity;
import net.flashpunk.graphics.Text;

public class DialogText extends Entity{

public function HelloWorld() 
{
	setHitbox(800, 600);
}

override public function update():void
{
	graphic = new Text("HERES A BUNCH OF TEXT TO DEMONSTRATE THE PROBLEM I AM HAVING THE ORGINAL TEXT IS KINDA WIERD TO TO THE SUBJECT MATTER OF THE GAME I AM MAKING BUT I GUESS IT DOESN'T REALLY MATTER BECAUSE PEOPLE WILL BE ABLE TO PLAY THE GAME WHEN IT IS FINISHED ANYWAY IM GONNA QUIT NOW");
}

}

And that’s about it. If you could help that would be great.


(christopf) #2

My solution would be to create a own var for the text like (dont know if it can be made easier, maybe someone else know?)

public var textField:Text = new Text("");

above the constructor.

and then a function regarding the text settings into the begin function

override public function begin():void
{
   super.begin();

   textProperties()
}

private function textProperties():void
{
   textField.width = 240;      //your width
   textField.wordWrap = true   //so the text is getting wrapped
}

override public function update():void
{
   super.update();

   textField.text = "blabliblub"
}

maybe there is a shorter way without creating a extra instance but thats how i did it (=

hope it works