|
nitram_cero (2bam)
|
 |
« on: Mon, Aug 10, 2009 » |
|
 I added this hack to solve it. It probably won't work for multilines, and I don't know the performance hit (seems null to me anyway) New/Modified lines: var metrics:TextLineMetrics = _tf.getLineMetrics(0); var fixupX:Number = -(metrics.x - Math.floor(metrics.x));
_mtx.translate(fixupX+n.x+(width>>1),n.y+(height>>1));
Whole code (FlxText): override public function update():void { super.update(); var n:Point = new Point(); getScreenXY(n); if((_ox != n.x) || (_oy != n.y) || (_oa != angle)) { var metrics:TextLineMetrics = _tf.getLineMetrics(0); var fixupX:Number = -(metrics.x - Math.floor(metrics.x)); _mtx = new Matrix(); _mtx.translate(-(width>>1),-(height>>1)); _mtx.rotate(Math.PI * 2 * (angle / 360)); _mtx.translate(fixupX+n.x+(width>>1),n.y+(height>>1)); _ox = n.x; _oy = n.y; } } Regards -Martín
|
|
|
|
|
Logged
|
2BAMI Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
|
|
|
|
Adam Atomic
|
 |
« Reply #1 on: Mon, Aug 10, 2009 » |
|
Yea that won't work for multi-line centering, but should give more reliable/faster results for single line stuff than you can get from just manually punching in an offset or inserting spaces...FlxText needs some lovin from metric stuff for helping to assign a proper width and height too I think
|
|
|
|
|
Logged
|
|
|
|
|
nitram_cero (2bam)
|
 |
« Reply #2 on: Tue, Aug 11, 2009 » |
|
Perhaps the hack could grow a little more if the fixup value is cached only if it finds a '\n' on the string (on setText/construction). Else keep at 0.
Is there a way to actually kill font anti-aliasing? I've been reading about TextFormat and, for example, it says that sharpness only works if antiAliasType = "advanced". Because for some font sizes (diff. from 8, 16, 24,...) it always anti-alias, so this hack won't work.
Good luck! -Martín
|
|
|
|
|
Logged
|
2BAMI Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
|
|
|
|
Adam Atomic
|
 |
« Reply #3 on: Tue, Aug 11, 2009 » |
|
Yea, everything that I've read and looked up says there is no way to genuinely anti-alias the font rendering reliably even AT the fixed, proper sizes...some fonts you just get lucky and they work decently when left-justified  I think ideally flixel should ahve the ability to do its own justification evnetually
|
|
|
|
|
Logged
|
|
|
|
|
nitram_cero (2bam)
|
 |
« Reply #4 on: Tue, Sep 15, 2009 » |
|
Fixes! I made this hack work a bit better by changing stuff: * fixupX was negated when it shouldn't. * if the text wasn't moved, the fixup was never moved around, now it does when calling settext and the first time always (that's the reason for _dirty) private var _dirty:Boolean = true;
//@desc Called by the game loop automatically, updates the position and angle of the text override public function update():void { super.update(); var n:Point = new Point(); getScreenXY(n); if(_dirty || (_ox != n.x) || (_oy != n.y) || (_oa != angle)) { _dirty = false; var metrics:TextLineMetrics = _tf.getLineMetrics(0); var fixupX:Number = (metrics.x - Math.floor(metrics.x)); //trace(_tf.text + " metrics fixupX: "+fixupX); _mtx = new Matrix(); _mtx.translate(-(width>>1),-(height>>1)); _mtx.rotate(Math.PI * 2 * (angle / 360)); _mtx.translate(fixupX+n.x+(width>>1),n.y+(height>>1)); _ox = n.x; _oy = n.y; } }
//@desc Changes the text being displayed //@param Text The new string you want to display public function setText(Text:String):void { _tf.text = Text; _dirty=true; } Good luck! -Martín
|
|
|
|
|
Logged
|
2BAMI Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
|
|
|
|
mklee
|
 |
« Reply #5 on: Wed, Sep 16, 2009 » |
|
Sweet Nitram! You are a Flx-coding machine!
|
|
|
|
|
Logged
|
|
|
|
|
nitram_cero (2bam)
|
 |
« Reply #6 on: Wed, Sep 16, 2009 » |
|
heh  Actually I found ot that depending on the case it works better with a fixup that way or negated. This is too much of a hack... Flash's TextFields suck a great deal for pixel fonts.
|
|
|
|
|
Logged
|
2BAMI Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
|
|
|
increpare
Newbie

Posts: 18
|
 |
« Reply #7 on: Sat, Oct 24, 2009 » |
|
Fixes!
I made this hack work a bit better by changing stuff:
the hack worked very nicely, but I had to add in a check to see if the text was aligned to center, otherwise it screwed up some right-aligned text 
|
|
|
|
|
Logged
|
|
|
|
|
nitram_cero (2bam)
|
 |
« Reply #8 on: Wed, Oct 28, 2009 » |
|
Hi increpare!, it's good to see you around here too. Heheh, I'm glad it worked out for you. In my local version I enhanced it a little bit and set the fixup only at setText() instead of on each render, also checking if is centered there  Regards
|
|
|
|
|
Logged
|
2BAMI Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
|
|
|
|