-
-
Save dcampos/7ba790809f8bf3219f0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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; | |
| import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; | |
| public class ShatterTest extends ApplicationAdapter{ | |
| private Stage stage; | |
| @Override | |
| public void create() { | |
| Color[] colors = new Color[] { | |
| Color.RED, | |
| Color.GRAY, | |
| Color.BLUE, | |
| Color.GREEN, | |
| Color.YELLOW | |
| }; | |
| stage = new Stage(); | |
| for (int i=0; i<100; i++) { | |
| final Pixmap pix = new Pixmap(32, 32, Format.RGBA8888); | |
| pix.setColor(colors[MathUtils.random(colors.length-1)]); | |
| pix.fill(); | |
| final Texture tex = new Texture(pix); | |
| 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); | |
| if (stage.hit(x, y, true) instanceof Image) { | |
| Image img = (Image) stage.hit(x, y, true); | |
| Texture t = ((TextureRegionDrawable)img.getDrawable()).getRegion().getTexture(); | |
| for (int i=0; i<3; i++) { | |
| for (int j=0; j<3; j++) { | |
| TextureRegion reg = new TextureRegion(t, (int)(i | |
| * img.getWidth()/3), (int)(j * img.getHeight()/3), (int)(img.getHeight()/3), (int)(img.getHeight()/3)); | |
| 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); | |
| } | |
| img.remove(); | |
| } | |
| } | |
| } | |
| }); | |
| Gdx.input.setInputProcessor(stage); | |
| } | |
| @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(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment