Created
March 1, 2015 23:47
-
-
Save dzt/005e70cd07752d900e69 to your computer and use it in GitHub Desktop.
GDX Animation Example
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 com.petersoboyejo.firstgdxgame; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.g2d.Animation; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
import com.badlogic.gdx.graphics.g2d.TextureAtlas; | |
public class Game extends ApplicationAdapter { | |
private SpriteBatch batch; | |
private TextureAtlas bikerAtlas; | |
private Animation animation; | |
private float timePassed = 0; | |
@Override | |
public void create() { | |
batch = new SpriteBatch(); | |
bikerAtlas = new TextureAtlas(Gdx.files.internal("file.atlas")); | |
animation = new Animation(30f / 1, bikerAtlas.getRegions()); | |
} | |
@Override | |
public void dispose() { | |
batch.dispose(); | |
bikerAtlas.dispose(); | |
} | |
@Override | |
public void render() { | |
Gdx.gl.glClearColor(1, 1, 1, 1); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
batch.begin(); | |
// Time that passed since the animation started | |
// "true" tells your animations to loop | |
timePassed += Gdx.graphics.getDeltaTime(); | |
batch.draw(animation.getKeyFrame(timePassed, true), 300, 500); | |
batch.end(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment