Text
package;
import gecko.Color;
import gecko.Screen;
import gecko.components.draw.TextComponent;
import gecko.Gecko;
import gecko.Assets;
import gecko.systems.draw.DrawSystem;
class Game {
public function new(){
Gecko.currentScene.addSystem(DrawSystem.create());
Assets.load([
"Ubuntu-B.ttf",
"kenpixel_mini_square.ttf"
], _onAssetsLoad).start();
}
private function _onAssetsLoad() {
var entity1 = Gecko.currentScene.createEntity();
entity1.transform.position.set(20, 20);
entity1.transform.anchor.set(0, 0);
entity1.addComponent(TextComponent.create("A basic line of text.", "Ubuntu-B.ttf", 50));
var entity2 = Gecko.currentScene.createEntity();
entity2.transform.position.set(Screen.centerX, Screen.centerY);
var text2:TextComponent = entity2.addComponent(TextComponent.create("A basic line of text in other color.", "Ubuntu-B.ttf", 30));
text2.color = Color.Red;
var entity3 = Gecko.currentScene.createEntity();
entity3.transform.position.set(150, Screen.centerY + 100);
entity3.addComponent(TextComponent.create("Hey! I'm other example,\nbut, i'm a multiline\nexample of text!!!", "kenpixel_mini_square.ttf", 20));
var entity4 = Gecko.currentScene.createEntity();
entity4.transform.position.set(400, Screen.centerY + 150);
entity4.addComponent(TextComponent.create("Hey! I'm the same example,\nbut, i'm a multiline\nand center aligned!", "kenpixel_mini_square.ttf", 20, "center"));
var entity5 = Gecko.currentScene.createEntity();
entity5.transform.position.set(650, Screen.centerY + 100);
entity5.addComponent(TextComponent.create("Hey! I'm the same example,\nbut, i'm a multiline\nand right aligned!", "kenpixel_mini_square.ttf", 20, "right"));
var entity6 = Gecko.currentScene.createEntity();
entity6.transform.position.set(650, Screen.centerY - 200);
var textToDraw = '
Multiline text,
it\'s stored in a variable
using \'\' in differents lines.
Also, i\'m playing with line spacing.
';
var text2:TextComponent = entity6.addComponent(TextComponent.create(textToDraw, "kenpixel_mini_square.ttf", 20, "center"));
text2.lineSpacing = 20;
var entity7 = Gecko.currentScene.createEntity();
entity7.transform.position.set(200, Screen.centerY - 100);
var text3:TextComponent = entity7.addComponent(TextComponent.create("I'm a a text in a simple line, but wrapping with 'lineWidth' to 200px.", "Ubuntu-B.ttf", 20));
text3.lineWidth = 200;
}
}
Source Code