Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.dermetfan.someLibgdxTests.screens;
- import net.dermetfan.libgdx.graphics.AnimatedSprite;
- import net.dermetfan.someLibgdxTests.SomeLibgdxTests;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Screen;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.Animation;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.TextureRegion;
- import com.badlogic.gdx.scenes.scene2d.InputEvent;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
- import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
- import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
- import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
- public class AnimatedButtonTest implements Screen {
- private Stage stage;
- @Override
- public void render(float delta) {
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- stage.act(delta);
- stage.draw();
- }
- @Override
- public void resize(int width, int height) {
- }
- @Override
- public void show() {
- stage = new Stage();
- Gdx.input.setInputProcessor(stage);
- // create the animation for the AnimatedSprite
- Animation animation = new Animation(1 / 3f, new TextureRegion(new Texture("img/1.png")), new TextureRegion(new Texture("img/2.png")), new TextureRegion(new Texture("img/3.png"));
- animation.setPlayMode(Animation.LOOP);
- // create the AnimatedSprite and set its keepSize to true
- AnimatedSprite animatedSprite = new AnimatedSprite(animation);
- animatedSprite.setKeepSize(true);
- // create the TextButtonStyle for the TextButton and set the up Drawable to a SpriteDrawable to pass the AnimatedSprite in
- TextButtonStyle tbs = new TextButtonStyle();
- tbs.font = new BitmapFont();
- tbs.up = new SpriteDrawable(animatedSprite);
- TextButton button = new TextButton("TEST", tbs);
- // add some test listener to the button
- button.addListener(new ClickListener() {
- @Override
- public void clicked(InputEvent event, float x, float y) {
- System.out.println("clicked");
- }
- });
- stage.addActor(button);
- }
- @Override
- public void hide() {
- dispose();
- }
- @Override
- public void pause() {
- }
- @Override
- public void resume() {
- }
- @Override
- public void dispose() {
- stage.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement