Created
November 11, 2015 11:54
-
-
Save picopicolab/21798e722d6d1c3385b3 to your computer and use it in GitHub Desktop.
文字表示サンプル実装
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.picopicolab.games.demo; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.graphics.FPSLogger; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.g2d.BitmapFont; | |
import com.badlogic.gdx.graphics.g2d.GlyphLayout; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
/** | |
* 文字表示サンプル実装 | |
*/ | |
public class DemoGame extends ApplicationAdapter { | |
private SpriteBatch batch; | |
private BitmapFont font; | |
private GlyphLayout layout; | |
private FPSLogger logger; | |
@Override | |
public void create() { | |
batch = new SpriteBatch(); | |
font = new BitmapFont(Gdx.files.internal("default.fnt")); // ビットマップファイル読込 | |
layout = new GlyphLayout(); | |
logger = new FPSLogger(); | |
} | |
@Override | |
public void render() { | |
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
layout.setText(font, "Hello, libGDX!"); // フォントと描画する文字列を設定 | |
float x = Gdx.graphics.getWidth() / 2 - layout.width / 2; // 文字が画面の中央となるようにX座標を設定 | |
float y = Gdx.graphics.getHeight() / 2 + layout.height / 2; // 文字が画面の中央となるようにY座標を設定 | |
// 画像描画 | |
batch.begin(); | |
layout.setText(font, "Hello, libGDX!!"); | |
font.draw(batch, "Hello, libGDX!!", x, y); | |
batch.end(); | |
// FPS 出力 | |
logger.log(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment