Skip to content

Instantly share code, notes, and snippets.

@metaphore
metaphore / ResizeTexture.java
Last active March 22, 2023 07:04
[LibGDX] Resize texture on load
Pixmap pixmap200 = new Pixmap(Gdx.files.internal("200x200.png"));
Pixmap pixmap100 = new Pixmap(100, 100, pixmap200.getFormat());
pixmap100.drawPixmap(pixmap200,
0, 0, pixmap200.getWidth(), pixmap200.getHeight(),
0, 0, pixmap100.getWidth(), pixmap100.getHeight()
);
Texture texture = new Texture(pixmap100);
pixmap200.dispose();
pixmap100.dispose();
@metaphore
metaphore / PixmapFromTexture.java
Last active December 7, 2015 19:57
[LibGDX] How to obtain pixmap from texture
TextureData textureData = getTexture().getTextureData();
if (!textureData.isPrepared()) {
textureData.prepare();
}
Pixmap pixmap = textureData.consumePixmap();
@metaphore
metaphore / TintableRegionDrawable.java
Last active November 19, 2015 19:28
[LibGDX] Drawable that has own color
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
public class TintableRegionDrawable extends TextureRegionDrawable {
private static final Color tmpColor = new Color();
private final Color tintColor = new Color(Color.WHITE);
public void setTint(Color tint) {
@metaphore
metaphore / Test.java
Last active November 22, 2019 12:41
[LibGDX] Remove actor from parent after animation
Group group;
Actor actor;
// ...
group.addActor(actor);
// ...
// Remove target actor after animation has been finished
@metaphore
metaphore / RoundCornerFrameLayout.java
Created December 9, 2015 18:32
[Android] Frame layout with rounded corners
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/**
* Frame layout that has rounded corners (it clips content too).
@metaphore
metaphore / FadeWidget.java
Last active December 10, 2015 20:20
[LibGDX] Actor for fade in/out effect
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
@metaphore
metaphore / RenameLayers.jsx
Last active May 10, 2020 13:25
Simple Photoshop script that renames selected layers
#target photoshop
function main() {
if (app.activeDocument == null) {
alert("You should open some document to execute that script" + selectedLayers.length);
return;
}
selectedLayers = getSelectedLayers();
if (selectedLayers.length == 0) {
@metaphore
metaphore / corona-imagesheet.lua
Created September 8, 2016 16:08
Old corona image sheet format exporter for TexturePackerGUI
--
-- created with TexturePacker (http://www.codeandweb.com/texturepacker)
--
-- {{smartUpdateKey}}
--
-- local sheetInfo = require("mysheet")
-- local myImageSheet = graphics.newImageSheet( "mysheet.png", sheetInfo:getSheet() )
-- local sprite = display.newSprite( myImageSheet , {frames={sheetInfo:getFrameIndex("sprite")}} )
--
@metaphore
metaphore / StringRender.java
Created October 29, 2017 19:19
BitmapFont string render to an image file.
BitmapFont font = interfaceService.getSkin().getFont("default-font");
GlyphLayout glyphLayout = new GlyphLayout(font, getString("langZhTw"));
final int w = MathUtils.ceil(glyphLayout.width + 2f);
final int h = MathUtils.ceil(glyphLayout.height + 2f);
OrthographicCamera cam = new OrthographicCamera(w, h);
cam.setToOrtho(false, w, h);
cam.update();
@metaphore
metaphore / ShaderAlphaTest.java
Created September 24, 2019 13:15
GDX VFX transparency rendering test
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;