图片显示
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
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;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture texture;
TextureRegion textureRegion;
Sprite sprite;
int iconWidth = 128;
int iconHeight = 256;
int padding = 100;
@Override
public void create () {
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("data/animation.png"));
textureRegion = new TextureRegion(texture, 0, 0, iconWidth, iconHeight);
sprite = new Sprite(textureRegion);
sprite.setSize(iconWidth * 3, iconHeight * 3);
sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
sprite.setPosition(padding + iconWidth + iconWidth*2, padding);
}
@Override
public void dispose () {
batch.dispose();
texture.dispose();
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 1, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(texture, padding, padding, iconWidth, iconHeight);
batch.draw(textureRegion, padding+iconWidth, padding, iconWidth*2, iconHeight*2);
sprite.draw(batch);
batch.end();
}
}