Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mygdx.game;
- import com.badlogic.gdx.Game;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.utils.ScreenUtils;
- public class MyGdxGame extends Game {
- SpriteBatch batch;
- Texture img;
- float x = 0, y = 0;
- public static final float SPEED = 150;
- @Override
- public void create () {
- batch = new SpriteBatch();
- img = new Texture("badlogic.jpg");
- }
- @Override
- public void render () {
- ScreenUtils.clear(0, 1, 0, 1);
- if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
- y += SPEED * Gdx.graphics.getDeltaTime();
- }
- if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
- y -= SPEED * Gdx.graphics.getDeltaTime();
- }
- if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
- x -= SPEED * Gdx.graphics.getDeltaTime();
- }
- if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
- x += SPEED * Gdx.graphics.getDeltaTime();
- }
- batch.begin();
- batch.draw(img, x, y);
- batch.end();
- }
- @Override
- public void dispose () {
- batch.dispose();
- img.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment