MT4J文档翻译(4)---开发文档(1) HelloWorld
Hello World
这个教程通过一步一步构建MT4j 下的一个HelloWorld应用程序图解出MT4j应用程序下的基本结构和组件。
源代码如下:
MT4j/examples/helloWorld/startHelloWorld.java
package helloWorld; import org.mt4j.MTApplication; public class StartHelloWorld extends MTApplication { public static void main(String[] args) {initialize(); //初始化} @Overridepublic void startUp() {addScene(new HelloWorldScene(this, "Hello World Scene"));//添加场景} }?下面是场景的代码:
? MT4j/examples/helloWorld/HelloWorldScene.java
package helloWorld; import org.mt4j.MTApplication;import org.mt4j.components.TransformSpace;import org.mt4j.components.visibleComponents.font.FontManager;import org.mt4j.components.visibleComponents.widgets.MTTextArea;import org.mt4j.sceneManagement.AbstractScene;import org.mt4j.util.math.Vector3D; public class HelloWorldScene extends AbstractScene { public HelloWorldScene(MTApplication mtApplication, String name) {super(mtApplication, name); //Disable frustum culling for this scene - optionalthis.getCanvas().setFrustumCulling(false);//Set the background colorthis.setClearColor(new MTColor(146, 150, 188, 255)); //Create a textfieldMTTextArea textField = new MTTextArea(mtApplication, FontManager.getInstance().createFont(mtApplication, "arial.ttf", 50, //Font sizenew MTColor(255, 255, 255, 255), //Font fill colornew MTColor(255, 255, 255, 255))); //Font outline colortextField.setNoFill(true);textField.setNoStroke(true);textField.setText("Hello World!");//Add the textfield to our canvasthis.getCanvas().addChild(textField); //Center the textfield on the screentextField.setPositionGlobal(new Vector3D(mtApplication.width/2f, mtApplication.height/2f));} public void init() { } public void shutDown() {} }?