Skip to content

Instantly share code, notes, and snippets.

@piotr-j
piotr-j / GWTGXXFilePicker.java
Created June 27, 2019 21:01
GWT GDX file picker with jsni
package com.example;
interface Listener {
void picked (String b64Image, Pixmap pixmap);
void cancelled ();
void failed ();
}
public void pickFile (Listener listener) {
_pickFile(listener);
public boolean convertSpriteVertices = true;
/** Draws a rectangle using the given vertices. There must be 4 vertices, each made up of 6 elements in this order: x, y, lightColor, darkColor,
* u, v. The {@link #getColor()} and {@link #getDarkColor()} from the TwoColorPolygonBatch is not applied. */
@Override
public void draw (Texture texture, float[] spriteVertices, int offset, int count) {
if (!drawing) throw new IllegalStateException("begin must be called before draw.");
final short[] triangles = this.triangles;
final float[] vertices = this.vertices;
graphics.getView().setOnTouchListener(new View.OnTouchListener() {
@Override public boolean onTouch (View view, MotionEvent event) {
final int action = event.getAction() & MotionEvent.ACTION_MASK;
int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN: {
Gdx.app.log("DOWN", pointerIndex + " -> " + event.getPressure(pointerIndex));
} break;
case MotionEvent.ACTION_UP:
@piotr-j
piotr-j / ParticleEffectAtlasBug.java
Created February 2, 2017 12:58
Particle effect problem with packed, whitespace stripped assets
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEmitter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
@piotr-j
piotr-j / PolygonShapeTest.java
Created June 17, 2016 11:44 — forked from xoppa/PolygonShapeTest.java
Shows how to render primitive shapes using Batch, without using ShapeRenderer. Requires at least libGDX 1.6.4 or latest nightly.
package com.badlogic.gdx.tests.g2d;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
@piotr-j
piotr-j / perlin.py
Created June 6, 2016 19:00 — forked from eevee/perlin.py
Perlin noise in Python
"""Perlin noise implementation."""
# Licensed under ISC
from itertools import product
import math
import random
def smoothstep(t):
"""Smooth curve with a zero derivative at 0 and 1, making it useful for
interpolating.
public class PolyBatchTest extends ApplicationAdapter {
PolygonSpriteBatch batch;
@Override public void create () {
Pixmap white = new Pixmap(3, 3, Pixmap.Format.RGBA8888);
white.setColor(Color.WHITE);
white.drawRectangle(0, 0, 3, 3);
Texture texture = new Texture(white);
white.dispose();
PolygonRegion region = new PolygonRegion(new TextureRegion(texture), new float[]{0, 0, 0, 3, 3, 3, 3, 0}, new short[]{0,1,2,0,3,2});
// 6, so we cant fit 2 regions
TiledMapTileLayer base = (TiledMapTileLayer)map.getLayers().get(0);
int[][] collision = new int[base.getWidth()][base.getHeight()];
for (int x = base.getWidth() - 1; x >= 0; x--) {
for (int y = base.getHeight() - 1; y >= 0; y--) {
TiledMapTileLayer.Cell cell = base.getCell(x, y);
if (cell == null) {
Gdx.app.error(TAG, "Null cell at: " + x + " " + y);
continue;
}
TiledMapTile tile = cell.getTile();
@piotr-j
piotr-j / gist:2abd40be33b94dbfae27
Last active August 29, 2015 14:24
Modified ligth shader
rayHandler = new RayHandler(world);
rayHandler.setAmbientLight(0f, 0f, 0f, 0.5f);
rayHandler.setBlurNum(0);
rayHandler.setLightShader(createStepLightShader());
private ShaderProgram createStepLightShader () {
final String vertexShader =
"attribute vec4 vertex_positions;\n" //
+ "attribute vec4 quad_colors;\n" //