forked from fastjengine/FastJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
67 lines (53 loc) · 2.56 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package tech.fastj.examples.text2d;
import tech.fastj.engine.FastJEngine;
import tech.fastj.graphics.display.FastJCanvas;
import tech.fastj.graphics.game.Text2D;
import tech.fastj.math.Pointf;
import tech.fastj.systems.control.SimpleManager;
import java.awt.Color;
import java.awt.Font;
public class Main extends SimpleManager {
@Override
public void init(FastJCanvas canvas) {
/* Text2D */
/* In order to create a Text2D, you just need to have a String containing text. */
// The text is pretty simple -- just a String containing text.
String text = "Hello, FastJ Text2D!";
// Simple Text2D creation can be done with Text2D.fromText(text)
Text2D message = Text2D.fromText(text);
/* Super simple! Now, this alone does not cause the text to render to the screen. In order
* for it to be rendered, you need to add it as a game object to the drawable manager. */
drawableManager().addGameObject(message);
/* If you comment out the line above, you'll see that the text does not get rendered. */
/* You can set the following properties of a Text2D:
* - Text (String)
* - Fill paint (solid color or a gradient)
* - Font
* - Transformation (translation, rotation, scale)
* - ShouldRender (whether the Polygon2D should be rendered to the screen)
*
* To show this off, we'll create a Text2D object with the following attributes:
* - Text containing "Interesting Text2D ya got there..."
* - Magenta color
* - Times New Roman font, size 12 italic
* - Translated by (20, 10)
* - Rotation by 30 degrees
* - Scaled down to 50% (0.5) */
String interestingText = "Interesting Text2D ya got there...";
Font interestingFont = new Font("Times New Roman", Font.ITALIC, 12);
Pointf largeSquareTranslation = new Pointf(20f, 10f);
float largeSquareRotation = 30f;
Pointf largeSquareScale = new Pointf(0.5f, 0.5f);
Text2D interestingText2D = Text2D.create(interestingText)
.withFill(Color.magenta)
.withFont(interestingFont)
.withTransform(largeSquareTranslation, largeSquareRotation, largeSquareScale)
.build();
// And of course, we need to add our interesting text to the drawable manager's game objects.
drawableManager().addGameObject(interestingText2D);
}
public static void main(String[] args) {
FastJEngine.init("Hello, Text2D!", new Main());
FastJEngine.run();
}
}