Skip to content

Instantly share code, notes, and snippets.

@implicit-invocation
Created September 22, 2018 21:02
Show Gist options
  • Save implicit-invocation/505971ab0a66418a570c25ccb8008ba2 to your computer and use it in GitHub Desktop.
Save implicit-invocation/505971ab0a66418a570c25ccb8008ba2 to your computer and use it in GitHub Desktop.
package com.mygdx.game;
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.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.TimeUtils;
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
private Sprite trimmedSprite;
private Sprite sprite;
@Override
public void create() {
batch = new SpriteBatch();
TextureAtlas textureAtlas = new TextureAtlas("test.atlas");
trimmedSprite = textureAtlas.createSprite("charge0001");
sprite = new Sprite(new Texture("charge0001.png"));
sprite.setOriginCenter();
trimmedSprite.setColor(Color.RED);
sprite.setColor(Color.BLUE);
}
int rotation = 0;
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
rotation += 1;
batch.begin();
sprite.setRotation(rotation);
trimmedSprite.setRotation(rotation);
trimmedSprite.draw(batch);
if ((TimeUtils.millis() / 1000) % 2 == 0) {
sprite.draw(batch);
}
batch.end();
}
@Override
public void dispose() {
batch.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment