Author Topic: FlxText setFormat problem  (Read 1836 times)

Michael71

  • Member
  • **
  • Posts: 37
  • Karma: +0/-0
  • War... War never changes....
    • View Profile
    • NetGfx
FlxText setFormat problem
« on: Wed, Jun 1, 2011 »
Hello, I've had a field day today in the forums but I'm just trying to get around the different parts of Flixel.

Anyhow here's my problem, when I use setFormat with whatever options the Text simply does not show. If I omit it, it displays normally.


I've tried everything that I could find in the forums:
I've Embedded a font
I've set options like (_hud.color=0xffffff; etc...)
I've changed location of the text


nothing seems to work, my guess is that it has something to do with Flex 4.5 and how it renders text but thought I should ask if someone knows something more here.

Code is on create() and it is very simple:
Code: [Select]
var playerHealth:String = "100";
_hud = new FlxText(FlxG.width-25,FlxG.height-35,100,playerHealth);
_hud.setFormat(null,30,0xff0000,"center");
add(_hud);

Would be grateful if someone could help on this one.

cai

  • Contributor
  • ****
  • Posts: 465
  • Karma: +0/-0
  • the illest of villains
    • View Profile
    • Brandon Cash
Re: FlxText setFormat problem
« Reply #1 on: Wed, Jun 1, 2011 »
Color values in AS3 are typically in the 0xAARRGGBB format, where AA is the alpha value.  If you omit that, then it will be 0, or fully transparent.  Try using 0xffff0000 instead.
Follow me on Twitter | Come join us at #flixel on irc.freenode.net!

Michael71

  • Member
  • **
  • Posts: 37
  • Karma: +0/-0
  • War... War never changes....
    • View Profile
    • NetGfx
Re: FlxText setFormat problem
« Reply #2 on: Wed, Jun 1, 2011 »
unfortunately no that didn't work either  :(

Also tried to embed the default Nokia font

Code: [Select]
[Embed(source="assets/nokiafc22.ttf", fontFamily="Nokia", embedAsCFF="true")]
public static var FontNokia:String;;

no luck...
« Last Edit: Wed, Jun 1, 2011 by Michael71 »

Michael71

  • Member
  • **
  • Posts: 37
  • Karma: +0/-0
  • War... War never changes....
    • View Profile
    • NetGfx
Re: FlxText setFormat problem
« Reply #3 on: Wed, Jun 1, 2011 »
Finally I found out what was causing the text not to appear, although I'm not sure why it was appearing if no format was set.

I was finally able to see text when I removed the FlxG.width and replaced it with a number like 300, it appears that the game world was much larger and the text would go off-screen. It is strange however since I specifically set it to 480x600.

The Text reaches the end of the screen at 360 pixels.

It is odd, however I thought to post this in case anyone had any problems.
I should also mention that I was running the application in the Flex mobile emulator.

Arkeus

  • Contributor
  • ****
  • Posts: 321
  • Karma: +1/-0
    • View Profile
    • I, Arkeus
Re: FlxText setFormat problem
« Reply #4 on: Wed, Jun 1, 2011 »
Looking at your original code, you were passing FlxG.width - 25 for the x value, and 100 for the width, and centering it, which means the center of the text would be 25 pixels to the right of the screen, and if the text was less than 50 pixels wide, would be off the screen.

Not sure if that's what the problem was later, but be careful of the order of the parameters.

Michael71

  • Member
  • **
  • Posts: 37
  • Karma: +0/-0
  • War... War never changes....
    • View Profile
    • NetGfx
Re: FlxText setFormat problem
« Reply #5 on: Thu, Jun 2, 2011 »
Isn't FlxG.width-25 25 pixels left of the screen?

I mean if screen = 480 - 25  = 455 right? With 0 being the start of the screen.
You are correct about the 100 though, the text was 25 pixels so it was much smaller.

Arkeus

  • Contributor
  • ****
  • Posts: 321
  • Karma: +1/-0
    • View Profile
    • I, Arkeus
Re: FlxText setFormat problem
« Reply #6 on: Thu, Jun 2, 2011 »
Isn't FlxG.width-25 25 pixels left of the screen?

I mean if screen = 480 - 25  = 455 right? With 0 being the start of the screen.
You are correct about the 100 though, the text was 25 pixels so it was much smaller.

Right. But the LEFT side of the text box was 25 pixels left of the screen. The text box was then set to 100 pixels width. So it started 25 pixels left of the right side of the screen, and it ended 75 pixels to the right of the right side of the screen (100 pixel width). Then you centered it, and the center of that box would be 25 pixels to the right side of the screen.

When you center text, it centers it in that width, and doesn't put the center at the x coordinate you specify. Can get very confusing sometimes.