Created
September 20, 2014 12:58
-
-
Save mrp1q7z/10e501151e914b4fba46 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.inputdemo; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.Input; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.Texture; | |
import com.badlogic.gdx.graphics.g2d.Sprite; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
public class GdxMain extends ApplicationAdapter { | |
private SpriteBatch batch; | |
private Texture texture; | |
private Sprite sprite; | |
@Override | |
public void create() { | |
float w = Gdx.graphics.getWidth(); | |
float h = Gdx.graphics.getHeight(); | |
batch = new SpriteBatch(); | |
texture = new Texture(Gdx.files.internal("img01.png")); | |
sprite = new Sprite(texture); | |
sprite.setPosition(w / 2 - sprite.getWidth() / 2, | |
h / 2 - sprite.getHeight() / 2); | |
} | |
@Override | |
public void dispose() { | |
batch.dispose(); | |
texture.dispose(); | |
} | |
@Override | |
public void render() { | |
Gdx.gl.glClearColor(1, 1, 1, 1); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) { | |
if (Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT)) { | |
sprite.translateX(-1f); | |
} else { | |
sprite.translateX(-10.0f); | |
} | |
} | |
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) { | |
if (Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT)) { | |
sprite.translateX(1f); | |
} else { | |
sprite.translateX(10.0f); | |
} | |
} | |
batch.begin(); | |
sprite.draw(batch); | |
batch.end(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment