Java tutorial
/* * Copyright 2016 Surasek Nusati <surasek@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package th.skyousuke.libgdx.xomaisad; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.utils.viewport.FitViewport; public class MainMenuScreen implements Screen { private static final String TITLE_TEXT = "XO ?"; private static final String START_TEXT = "?"; private final float titleTextWidth; private final float startTextWidth; private OrthographicCamera camera; private FitViewport viewport; private final XOMaiSad game; public MainMenuScreen(final XOMaiSad game) { this.game = game; camera = new OrthographicCamera(); viewport = new FitViewport(XOMaiSad.SCREEN_WIDTH, XOMaiSad.SCREEN_HEIGHT, camera); game.glyphLayout.setText(Assets.instance.font, TITLE_TEXT); titleTextWidth = game.glyphLayout.width; game.glyphLayout.setText(Assets.instance.font, START_TEXT); startTextWidth = game.glyphLayout.width; } @Override public void show() { } @Override public void render(float delta) { if (Gdx.input.justTouched()) { game.setScreen(new GameScreen(game)); } Gdx.gl.glClearColor(0.8f, 0.8f, 0.8f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); game.batch.setProjectionMatrix(camera.combined); game.batch.begin(); Assets.instance.font.draw(game.batch, TITLE_TEXT, -titleTextWidth / 2, 100); Assets.instance.font.draw(game.batch, START_TEXT, -startTextWidth / 2, 0); game.batch.end(); } @Override public void resize(int width, int height) { viewport.update(width, height); } @Override public void pause() { } @Override public void resume() { } @Override public void hide() { } @Override public void dispose() { } }