Skip to content

Instantly share code, notes, and snippets.

@jarbot
Created October 31, 2016 18:23
Show Gist options
  • Save jarbot/cf289aa0b0bda0700c0560d445e1b2bf to your computer and use it in GitHub Desktop.
Save jarbot/cf289aa0b0bda0700c0560d445e1b2bf to your computer and use it in GitHub Desktop.
Repro TextField Performance issue.
package;
import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.KeyboardEvent;
import openfl.Lib;
import openfl.text.Font;
import openfl.text.TextField;
import openfl.text.TextFieldAutoSize;
import openfl.text.TextFormat;
import openfl.text.TextFormatAlign;
import openfl.events.Event;
import openfl.events.MouseEvent;
class Main extends Sprite {
private var demo:Int = 0;
private static inline var MAX_DEMO:Int = 5;
private var alpha_step:Float = 0.25;
private var comparison:Bitmap;
private var label:TextField;
public function new () {
super ();
var lastY:Float = 0;
var fieldCount:Int = 0;
var f = font("nokiafc22.ttf");
stage.addEventListener (MouseEvent.CLICK, function(e:MouseEvent):Void {
makeText(50, lastY, TextFormatAlign.CENTER, 16, f, true);
makeText(150, lastY, TextFormatAlign.CENTER, 16, f, true);
makeText(250, lastY, TextFormatAlign.CENTER, 16, f, true);
makeText(350, lastY, TextFormatAlign.CENTER, 16, f, true);
makeText(450, lastY, TextFormatAlign.CENTER, 16, f, true);
lastY += 10;
fieldCount += 5;
trace('text field count: ', fieldCount);
});
}
function clear():Void
{
while (numChildren > 0)
{
removeChild(getChildAt(0));
}
}
function font(str:String):String
{
var f = Assets.getFont("assets/"+str);
if (f != null)
{
return f.fontName;
}
return str;
}
function makeText(X:Float, Y:Float, align, size:Int, ?font:String, ?embed:Bool=false)
{
var textField = new TextField();
textField.embedFonts = embed;
textField.defaultTextFormat = new TextFormat(font, size, 0x000000, null, null, null, null, null, align, null, null, null, 20);
//textField.selectable = false;
//textField.border = true;
//textField.borderColor = 0x000000;
//textField.width = 700;
//textField.multiline = true;
//textField.wordWrap = true;
textField.autoSize = TextFieldAutoSize.NONE;
textField.x = X;
textField.y = Y;
textField.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
addChild (textField);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment