Created
August 31, 2014 01:11
-
-
Save mrp1q7z/0146742ceeeee518d3e4 to your computer and use it in GitHub Desktop.
libGDX sample
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 name.taoka.ugeee.basicgraphics; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.graphics.Color; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.Pixmap; | |
import com.badlogic.gdx.graphics.Texture; | |
import com.badlogic.gdx.graphics.g2d.Sprite; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
public class MyGdxGame extends ApplicationAdapter { | |
SpriteBatch batch; | |
Texture img; | |
private Sprite sprite; | |
private Pixmap pixmap; | |
@Override | |
public void create() { | |
batch = new SpriteBatch(); | |
// img = new Texture(Gdx.files.internal("jet.png")); | |
// sprite = new Sprite(img); | |
// Pixmapはメモリ上で生イメージを生成するもの | |
pixmap = new Pixmap(256, 128, Pixmap.Format.RGBA8888); | |
// 赤で塗りつぶす | |
pixmap.setColor(Color.RED); | |
pixmap.fill(); | |
// 2本の線でXを引く | |
pixmap.setColor(Color.BLACK); | |
pixmap.drawLine(0, 0, pixmap.getWidth() - 1, pixmap.getHeight() - 1); | |
pixmap.drawLine(0, pixmap.getHeight() - 1, pixmap.getWidth() - 1, 0); | |
// 中心に円を描く | |
pixmap.setColor(Color.YELLOW); | |
pixmap.drawCircle(pixmap.getWidth() / 2, pixmap.getHeight() / 2, | |
pixmap.getHeight() / 2 - 1); | |
img = new Texture(pixmap); | |
sprite = new Sprite(img); | |
// Pixmapは不要になったら後処理をする | |
pixmap.dispose(); | |
} | |
@Override | |
public void render() { | |
// 黒(R=0,G=0,B=0)で初期化 | |
Gdx.gl.glClearColor(0, 0, 0, 1); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
batch.begin(); | |
sprite.setPosition(0, 0); | |
sprite.draw(batch); | |
sprite.setPosition(Gdx.graphics.getWidth() / 2, | |
Gdx.graphics.getHeight() / 2); | |
sprite.draw(batch); | |
batch.end(); | |
} | |
@Override | |
public void dispose() { | |
batch.dispose(); | |
img.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment