List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap
public Pixmap(byte[] encodedData, int offset, int len)
From source file:com.mbrlabs.mundus.history.commands.TerrainPaintCommand.java
License:Apache License
public void setAfter(Pixmap data) { after = new Pixmap(data.getWidth(), data.getHeight(), data.getFormat()); after.drawPixmap(data, 0, 0); }
From source file:com.mbrlabs.mundus.history.commands.TerrainPaintCommand.java
License:Apache License
public void setBefore(Pixmap data) { before = new Pixmap(data.getWidth(), data.getHeight(), data.getFormat()); before.drawPixmap(data, 0, 0); }
From source file:com.mekomidev.gdxengine.utils.loaders.GifDecoder.java
License:Open Source License
public Animation<TextureRegion> getAnimation(PlayMode playType) { int nrFrames = getFrameCount(); // if(nrFrames > 100) // {/*from ww w . j a v a2s . com*/ // nrFrames=100; // } advance(); Pixmap frame = getNextFrame(); int width = frame.getWidth(); int height = frame.getHeight(); int vzones = (int) Math.sqrt((double) nrFrames); int hzones = vzones; while (vzones * hzones < nrFrames) vzones++; int v, h; Pixmap target = new Pixmap(width * hzones, height * vzones, Pixmap.Format.RGBA8888); int frameCountCurrent = 0; for (h = 0; h < hzones; h++) { for (v = 0; v < vzones; v++) { if (frameCountCurrent < nrFrames) { frameCountCurrent++; advance(); frame = getNextFrame(); target.drawPixmap(frame, h * width, v * height); int pixelSize = (int) (frame.getWidth() * 0.025f); target.setColor(Color.BLACK); int xPos, yPos; xPos = h * width; yPos = v * height; // target.fillRectangle(xPos, yPos, frame.getWidth(), pixelSize); // target.fillRectangle(xPos + frame.getWidth()-pixelSize, yPos, pixelSize, frame.getHeight()); // target.fillRectangle(xPos, yPos + frame.getHeight()-pixelSize, frame.getWidth(), pixelSize); // target.fillRectangle(xPos, yPos,pixelSize, frame.getHeight()); } } } Texture texture = new Texture(target); //target.dispose(); target = null; Array<TextureRegion> texReg = new Array<TextureRegion>(); TextureRegion tr = new TextureRegion(texture); for (h = 0; h < hzones; h++) { for (v = 0; v < vzones; v++) { int frameID = v + h * vzones; if (frameID < nrFrames) { tr = new TextureRegion(texture, h * width, v * height, width, height); texReg.add(tr); } } } float frameDuration = (float) getDelay(0); frameDuration /= 500; // convert milliseconds into seconds Animation<TextureRegion> result = new Animation<>(frameDuration, texReg, playType); texReg.clear(); frames.clear(); prefix = null; suffix = null; pixelStack = null; mainPixels = null; mainScratch = null; copyScratch = null; return result; //return animation object }
From source file:com.momia.asg.screens.MainMenu.java
License:Apache License
public MainMenu(final ASG game) { this.game = game; batch = new SpriteBatch(); stage = new Stage(); Gdx.input.setInputProcessor(stage);/*ww w.j a v a 2 s. c o m*/ // A skin can be loaded via JSON or defined programmatically, either is fine. Using a skin is optional but strongly // recommended solely for the convenience of getting a texture, region, etc as a drawable, tinted drawable, etc. skin = new Skin(); // Generate a 1x1 white texture and store it in the skin named "white". Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888); pixmap.setColor(Color.WHITE); pixmap.fill(); skin.add("white", new Texture(pixmap)); // Store the default libgdx font under the name "default". skin.add("default", new BitmapFont()); // Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font. TextButtonStyle textButtonStyle = new TextButtonStyle(); textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY); textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY); textButtonStyle.checked = skin.newDrawable("white", Color.BLUE); textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY); textButtonStyle.font = skin.getFont("default"); skin.add("default", textButtonStyle); // Create a table that fills the screen. Everything else will go inside this table. Table table = new Table(); table.setFillParent(true); stage.addActor(table); // Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a name other than "default". final TextButton button = new TextButton("New Game", skin); table.add(button); // Add a listener to the button. ChangeListener is fired when the button's checked state changes, eg when clicked, // Button#setChecked() is called, via a key press, etc. If the event.cancel() is called, the checked state will be reverted. // ClickListener could have been used, but would only fire when clicked. Also, canceling a ClickListener event won't // revert the checked state. button.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { if (button.isChecked()) game.setScreen(new Screen1(game)); } }); }
From source file:com.mygdx.game.screens.GameChooserScreen.java
private void create() { //Create a font BitmapFont font = new BitmapFont(); skin = new Skin(); skin.add("default", font); //Create a texture Pixmap pixmap = new Pixmap((int) Gdx.graphics.getWidth() / 4, (int) Gdx.graphics.getHeight() / 10, Pixmap.Format.RGB888); pixmap.setColor(Color.WHITE); pixmap.fill();//w ww.j a v a 2s .c o m skin.add("background", new Texture(pixmap)); //Create a button style TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); textButtonStyle.up = skin.newDrawable("background", Color.GRAY); textButtonStyle.down = skin.newDrawable("background", Color.DARK_GRAY); textButtonStyle.checked = skin.newDrawable("background", Color.DARK_GRAY); textButtonStyle.over = skin.newDrawable("background", Color.LIGHT_GRAY); textButtonStyle.font = skin.getFont("default"); skin.add("default", textButtonStyle); }
From source file:com.mygdx.game.Splash.java
public void create() { batch = new SpriteBatch(); stage = new Stage(); Gdx.input.setInputProcessor(stage);//from w w w . j a v a2s .c o m skin = new Skin(); Pixmap pixmap = new Pixmap(100, 100, Format.RGBA8888); pixmap.setColor(Color.GREEN); pixmap.fill(); skin.add("white", new Texture(pixmap)); BitmapFont bfont = new BitmapFont(); //bfont.scale(1); skin.add("default", bfont); TextButtonStyle textButtonStyle = new TextButtonStyle(); textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY); textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY); textButtonStyle.checked = skin.newDrawable("white", Color.BLUE); textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY); textButtonStyle.font = skin.getFont("default"); skin.add("default", textButtonStyle); final TextButton textButton = new TextButton("PLAY", textButtonStyle); textButton.setPosition(200, 200); stage.addActor(textButton); stage.addActor(textButton); stage.addActor(textButton); textButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { //System.out.println("Clicked! Is checked: " + button.isChecked()); textButton.setText("Starting new game"); //g.setScreen( new GameWorking()); } }); }
From source file:com.mygdx.game.utilities.PerlinNoiseGenerator.java
License:Apache License
public Pixmap generatePixmap(int width, int height, int min, int max, int octaveCount) { byte[] bytes = generateHeightMap(width, height, min, max, octaveCount); Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888); for (int i = 0, idx = 0; i < bytes.length; i++) { byte val = bytes[i]; pixmap.getPixels().put(idx++, val); pixmap.getPixels().put(idx++, val); pixmap.getPixels().put(idx++, val); pixmap.getPixels().put(idx++, (byte) 255); }/*from w w w . j a v a 2s . co m*/ return pixmap; }
From source file:com.mygdx.java.utils.ImageUtils.java
License:Apache License
public static void setScreenTextureRegion(TextureRegion textureRegion, byte[] bytes) { if (textureRegion == null) { throw new IllegalArgumentException("Input the TextureRegion is null."); }//from w w w . ja v a2 s. co m Texture tempTexture = textureRegion.getTexture(); if (tempTexture != null) { tempTexture.dispose(); tempTexture = null; } Pixmap pixmap = new Pixmap(bytes, 0, bytes.length); int width = pixmap.getWidth(); int height = pixmap.getHeight(); Texture texture = new Texture(width, height, pixmap.getFormat()); texture.draw(pixmap, 0, 0); textureRegion.setTexture(texture); textureRegion.setRegion(0, 0, width, height); pixmap.dispose(); }
From source file:com.mygdx.java.utils.ImageUtils.java
License:Apache License
public static void setScreenTextureRegionInThread(final TextureRegion textureRegion, final byte[] bytes) { if (textureRegion == null) { throw new IllegalArgumentException("Input the TextureRegion is null."); }/*from w w w .j a va 2s .c om*/ Gdx.app.postRunnable(new Runnable() { @Override public void run() { Texture tempTexture = textureRegion.getTexture(); if (tempTexture != null) { tempTexture.dispose(); textureRegion.setTexture(null); } Pixmap pixmap = new Pixmap(bytes, 0, bytes.length); int width = pixmap.getWidth(); int height = pixmap.getHeight(); // pixmap.setBlending(Blending.None); // Texture texture = new Texture(width, height, // pixmap.getFormat()); Texture texture = new Texture(pixmap, true); texture.draw(pixmap, 0, 0); textureRegion.setTexture(texture); textureRegion.setRegion(0, 0, width, height); pixmap.dispose(); } }); }
From source file:com.mygdx.screen.CreaMenu.java
private void createBasicSkin() { //Create a font skin = new Skin(); skin.add("default", font); //Create a texture Pixmap pixmap = new Pixmap((int) Gdx.graphics.getWidth() / 4, (int) Gdx.graphics.getHeight() / 10, Pixmap.Format.RGB888); pixmap.setColor(Color.WHITE); pixmap.fill();/*from w w w . j a v a 2 s . c om*/ skin.add("background", new Texture(pixmap)); //Create a button style TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); textButtonStyle.up = skin.newDrawable("background", Color.GRAY); textButtonStyle.down = skin.newDrawable("background", Color.DARK_GRAY); textButtonStyle.checked = skin.newDrawable("background", Color.DARK_GRAY); textButtonStyle.over = skin.newDrawable("background", Color.LIGHT_GRAY); textButtonStyle.font = skin.getFont("default"); skin.add("default", textButtonStyle); }