Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2014 20:04
Show Gist options
  • Select an option

  • Save anonymous/7dd798a9adae12ec8cbd to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/7dd798a9adae12ec8cbd to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jan 8, 2014.
    119 changes: 119 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,119 @@
    package net.deltaplay.tests;
    import com.badlogic.gdx.ApplicationAdapter;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.Color;
    import com.badlogic.gdx.graphics.GL10;
    import com.badlogic.gdx.graphics.Pixmap;
    import com.badlogic.gdx.graphics.Pixmap.Format;
    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.g2d.TextureRegion;
    import com.badlogic.gdx.math.MathUtils;
    import com.badlogic.gdx.scenes.scene2d.Actor;
    import com.badlogic.gdx.scenes.scene2d.InputEvent;
    import com.badlogic.gdx.scenes.scene2d.Stage;
    import com.badlogic.gdx.scenes.scene2d.actions.Actions;
    import com.badlogic.gdx.scenes.scene2d.ui.Image;
    import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;


    public class ShatterTest extends ApplicationAdapter{
    private Stage stage;

    private boolean destroied;

    @Override
    public void create() {
    stage = new Stage();

    final Pixmap pix = new Pixmap(32, 32, Format.RGBA8888);

    pix.setColor(Color.RED);
    pix.fill();

    final Texture tex = new Texture(pix);

    for (int i=0; i<100; i++) {

    final Image img = new Image(new Texture(pix));
    img.setPosition(MathUtils.random(stage.getWidth()), MathUtils.random(stage.getHeight()));


    stage.addActor(img);
    }

    stage.addCaptureListener(new ClickListener() {

    @Override
    public void clicked(InputEvent event, float x, float y) {
    System.err.println("clicked at " + x + "," + y);

    Actor img = stage.hit(x, y, true);

    if (img instanceof Image) {

    for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
    TextureRegion reg = new TextureRegion(tex, (int)(i
    * img.getWidth()/3), (int)(j * img.getHeight()/3), (int)(img.getHeight()/3), (int)(img.getHeight()/3));

    System.err.println(reg.getRegionX());

    final Image piece = new Image(reg);
    piece.setPosition(img.getX()+reg.getRegionX(), img.getY()+reg.getRegionY());

    float move = MathUtils.random(15f, 30f);

    float moveX = (i == 0 ? -move : (i == 2 ? move : MathUtils.random(-move, move)));
    float moveY = (j == 0 ? -move : (j == 2 ? move : MathUtils.random(-move, move)));

    piece.addAction(Actions.sequence(Actions.parallel(Actions.moveBy(moveX, moveY, 0.5f), Actions.fadeOut(0.5f)), Actions.run(new Runnable() {

    @Override
    public void run() {
    piece.remove();
    }
    })));

    stage.addActor(piece);

    System.err.println("here!");
    }

    img.remove();
    }

    destroied = true;

    }
    }

    });


    Gdx.input.setInputProcessor(stage);

    destroied = false;
    }

    @Override
    public void render() {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    stage.act();
    stage.draw();
    }

    @Override
    public void resize(int width, int height) {
    stage.setViewport(stage.getWidth(), stage.getHeight());

    super.resize(width, height);
    }

    @Override
    public void dispose() {
    // TODO Auto-generated method stub
    super.dispose();
    }

    }