-
-
Save dcampos/7ba790809f8bf3219f0a to your computer and use it in GitHub Desktop.
Revisions
-
dcampos revised this gist
Jan 8, 2014 . 1 changed file with 21 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,26 +14,34 @@ 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())); @@ -47,17 +55,17 @@ public void create() { 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()); @@ -76,13 +84,11 @@ public void run() { stage.addActor(piece); } img.remove(); } } } @@ -91,8 +97,6 @@ public void run() { Gdx.input.setInputProcessor(stage); } @Override -
dcampos revised this gist
Jan 8, 2014 . No changes.There are no files selected for viewing
-
dcampos revised this gist
Jan 8, 2014 . No changes.There are no files selected for viewing
-
There are no files selected for viewing
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 charactersOriginal 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(); } }