[source code] Android Development Tutorial - 74

+5 Bucky Roberts · February 25, 2015
package com.thenewboston.buckyblaster;

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 MyGdxGame extends ApplicationAdapter {

    private SpriteBatch batch;
    private TextureAtlas shooterAtlas;
    private Animation animation;
    private float timePassed = 0;

    @Override
    public void create () {
        batch = new SpriteBatch();

        shooterAtlas = new TextureAtlas(Gdx.files.internal("shooter.atlas"));
        animation = new Animation(1/30f, shooterAtlas.getRegions());
    }

    @Override
    public void dispose() {
        batch.dispose();
        shooterAtlas.dispose();
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(1,1,1,1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        batch.begin();
        timePassed += Gdx.graphics.getDeltaTime();
        batch.draw(animation.getKeyFrame(timePassed, true), 300, 500);
        batch.end();
    }

}

Post a Reply

Replies

Oldest  Newest  Rating
+3 Raman Ahuja · April 9, 2015
please post images used in this tutorial.
0 saurabh tanwar · October 16, 2015
from where i will get these bunch of the photos to be used in the animation
  • 1

Java / Android Development

107,303 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator