Hey guys I have a bunch of questions about font.
- how does one set up word wrap? I have a box I would like to keep my text in, but don’t want to break it up myself.
- is the font still kind of blurry sometimes? is this a bug? or was it fixed?
Hey guys I have a bunch of questions about font.
x = 20.3
).anyway to make so I don’t get a fractional value when using align to center?
also I don’t think I was using width and wordwrap so that’s working now.
so when using the center, left and right in the text.align, is there anyway to make sure it always uses a whole number?
I demand answers!
But really, I’m having this problem as well, and it’s a bit of an issue. Here’s some extra info I’ve gathered about it:
Image link (since I’m new and can’t post them directly…)
Firstly you should check, that the position is not on a fractional value (like x = 1.24). I’m sure you already did that but just in case you can do the following:
x = int(x);
y = int(y);
If that doesn’t work try this:
myText.smooth = false;
With “myText” being your text object. This should make it so the graphic has no antialiasing which might fix the problem.
I have a question for you though: How did you make one word colored red? I wanted to use that effect but never knew how to do it other than by using two texts overlaid which is a pain in the bum.
I fiddle with it a bit (with the default font, which seems the same one you’re using), but couldn’t replicate the blurry issue as shown by @ConnorUllmann, even positioning the text on fractional pixels.
Are you setting the size to a non-multiple of 8, or scaling it in some way? This could lead to problems as suggested by @zachwlewis, but doesn’t really explain why only the first line is affected.
Can we see some minimal code to reproduce it?
EDIT: @VoEC: richText
in combination with setStyle()
is one of the most powerful and less known things that the Text
class could do.
From the docs:
/**
* Set the style for a subset of the text, for use with
* the richText property.
* Usage:
text.setStyle("red", {color: 0xFF0000});
text.setStyle("big", {size: text.size*2});
text.richText = "<big>Hello</big> <red>world</red>";
*/
Here’s some of the code I’m using:
//Some constants used.
private const EDGE_MARGIN_X:int = 8;
private const EDGE_MARGIN_Y:int = 12;
// Initializing
textO = new Text("", 0, 0, { "size":8 } );
textO.setStyle("red", { color: 0xFF0000 } );
textO.setStyle("bigger", { size:12 } );
textO.width = FP.screen.width - EDGE_MARGIN_X * 2;
textO.wordWrap = true;
textO.smooth = false;
textO.align = "center";
textO.richText =
"It is a long established fact that a reader will be distracted by It is "+
"It is a long established fact that a reader will be distracted by It is "+
"It is a long established fact that a reader will be distracted by It is ";
// Render
textO.render(FP.buffer, new Point(EDGE_MARGIN_X, int(FP.screen.height * 3 / 4 + EDGE_MARGIN_Y)), new Point);
This text will make all three lines fuzz out, like this:
Other information if you’re really looking to reproduce it exactly:
Thanks for the testing code - used it all, up to the screen scale and size.
Aaand… confirmed O.o !
I’m getting the same results as you (even commenting out the richText related stuff it’s still blurry).
I’ve tried several combinations to spot the causes of the problem (fractional postions, use an entity, move text graphic, richText, updateTextBuffer not called?, different scaling (screen or font), sizes, etc.). All of them reproduced the issue and gave almost no clue on how to fix it.
After quite some testing I’ve got a case (with a custom font) in which a TextField works fine, while a FP Text does not. Still experimenting with it, but it probably has to do with font loading or more probably with wordWrapping in Flash.
Will post soon if I find the culprit (or some other clues)!
I messed around with this a little bit. Here’s what I found:
textO.width++
or textO.width--
fixes the problem. textO.width
is equal to 304
before modifications.38
. If I maintain this ratio with different numbers, the problem does not reappear.wordWrap
also fixes the problem.FP.screen.scale
to 1 also fixes the problem.render()
to using addGraphic()
and setting textO
's x
and y
properties does not fix anything.FP.screen.width
to 480
without changing FP.screen.height
, the problem goes away. If I change FP.screen.height
to 480
without changing FP.screen.width
, the problem persists. If I change both to 480
, the problem goes away. Note that changing the width alters the ratio of 38
mentioned above.So, I guess, temporary fix is to call textO.width -= 0.000001
before using it. I have no idea why this is a bug and I can’t think of anything right now. I’ll report back if I find anything.
The main problems seem to be:
FP.scale
to 2
ANDcenter
alignment for textO
ANDwordWrap
on textO
ANDwidth
and size
for textO
(when textO.size
= 8
and width
= 304
, things get blurry)Nice summary Jon!
Adding textO.width -= 0.000001
does fix the problem, but it’s only for that string. I put in the below string (which wasn’t blurry before), and it became blurry with that change:
"Discover here what has befallen the fallen."
What I’m basically getting from this is that it’s primarily dependent on the content of the text itself (which is why, in the images I put up earlier, most of the text gets along just fine) and the width of that line of text.
I think the TextField automatically offsets it to a fractional degree when it formats the center alignment, and I’m guessing that the Flashpunk code that attempts to fix the offset doesn’t actually handle it correctly; although, I couldn’t figure out why it wouldn’t fix this. The section I’m talking about is the lower half of the updateTextBuffer()
function in Text.as
If I had to guess, I would think that if (remainder > 0.1 && remainder < 0.9)
is the problem. The string might have 0 < remainder < 0.1
or 0.9 < remainder < 1
However, I didn’t see any notable change when I tried tinkering with these values (i.e. change 0.1 to 0.01 and 0.9 to 0.99).
I was having a similar issue in my game, and I wrote this quick fix:
counterText.smooth = false;
counterText.setTextProperty("antiAliasType", AntiAliasType.ADVANCED);
counterText.setTextProperty("sharpness", 200);
counterText.setTextProperty("thickness", 0);
It’s not a pretty solution, but it works until you can figure out what’s wrong with text.
A monospaced font might also fix your problem without all the hacks. I’m guessing it’s a kerning issue.
I think I found the problem!
It seems to have to do with TextLineMetrics
getting “dirty” and not reporting the correct values (see this related question on StackOverflow). So the offsetRequired
fix gets skipped due to wrong values.
The workaround I’ve found that seems to work fine with both plain and rich text is a single line to add in Text.updateTextBuffer()
:
var offsetRequired: Boolean = false;
var i:int;
// reassign text to force a recalc of TextLineMetrics and so be sure they report correct values
_field.htmlText = _field.htmlText;
var tlm: TextLineMetrics;
var remainder: Number;
var tlm_y:Number = 2;
for (i = 0; i < _field.numLines; i++) {
Can you confirm it works as expected?
Note that using richText and styling a subtext with a font size non-multiple of 8 (with the default font), will still not work. But setting it to 16, for example, will.
@ConnorUllmann: wunderbar!!
If all of you can test it thoroughly and prove it hasn’t any major drawbacks (haven’t found any yet, but really don’t know what reassigning the text involves underneath), I think it should be merged into the official repo.
What do you admins think (oh… let me summon the ones I know of @Draknek, @zachwlewis, @AbelToy)?
If there’s a pull request that fixes this, I’ll shove it in there, provided it doesn’t change the API.
Pull request coming your way!
Now Text requires three additional parameters. Plus, the order of the previous ones is slightly changed.
Naahhh, just kidding. It’s a one line fix!