From f5d9cbc011af8ffb7cd57eaaf3a146a04519d450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 12 May 2021 18:36:21 +0200 Subject: [PATCH] feat: dynamic texture coloring --- core/src/sagittarius/model/Arrow.java | 2 +- core/src/sagittarius/model/Planet.java | 2 +- core/src/sagittarius/model/Player.java | 27 ++++++++++++-------------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/core/src/sagittarius/model/Arrow.java b/core/src/sagittarius/model/Arrow.java index c68aadf..73d6996 100644 --- a/core/src/sagittarius/model/Arrow.java +++ b/core/src/sagittarius/model/Arrow.java @@ -83,7 +83,7 @@ public class Arrow extends EntityQuad { } @Override - public void draw (Batch batch, float parentAlpha) { + public void draw(Batch batch, float parentAlpha) { batch.draw(texture, getPosition().x - 0.8f * getWidth(), getPosition().y - getHeight()/2 - 10, 0.8f * this.getWidth(), this.getHeight()/2 + 10, getWidth(), 20 + getHeight(), 1, 1, getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false); super.draw(batch, parentAlpha); diff --git a/core/src/sagittarius/model/Planet.java b/core/src/sagittarius/model/Planet.java index bfc82ee..58b4f67 100644 --- a/core/src/sagittarius/model/Planet.java +++ b/core/src/sagittarius/model/Planet.java @@ -38,7 +38,7 @@ public class Planet extends EntityCircle { } @Override - public void draw (Batch batch, float parentAlpha) { + public void draw(Batch batch, float parentAlpha) { batch.draw(texture, getPosition().x - this.radius, getPosition().y - this.radius, this.radius, this.radius, 2 * this.radius, 2 * this.radius, 1, 1, getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false); super.draw(batch, parentAlpha); diff --git a/core/src/sagittarius/model/Player.java b/core/src/sagittarius/model/Player.java index 29781b8..d260716 100644 --- a/core/src/sagittarius/model/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -34,21 +34,18 @@ public class Player extends EntityQuad { pm.setBlending(Pixmap.Blending.None); for (int x = 0; x < pm.getWidth(); x++) { for (int y = 0; y < pm.getHeight(); y++) { - int p = pm.getPixel(x, y); - int r = (int)( (p & 0xff000000)>>24 ); - int g = (int)( (p & 0x00ff0000)>>16 ); - int b = (int)( (p & 0x0000ff00)>>8 ); - int a = (int)( p & 0x000000ff ); - if (p != 0) { - if (r == 255 && g == 255 && b == 255) { - r = 255; - g = 0; - b = 0; - a = 255; - p = (int)( r <<24 | g << 16 | b << 8 | a ); - } + + Color pc = new Color(); + Color.rgba8888ToColor(pc, pm.getPixel(x, y)); + + if (pc.equals(Color.WHITE)) { // pc.r == 1 && pc.g == 1 && pc.b == 1 + pc = Color.RED; + // pc.r = 1; + // pc.g = 0; + // pc.b = 0; } - pm.drawPixel(x, y, p); + + pm.drawPixel(x, y, Color.rgba8888(pc)); } } texture = new Texture(pm); @@ -64,7 +61,7 @@ public class Player extends EntityQuad { } @Override - public void draw (Batch batch, float parentAlpha) { + public void draw(Batch batch, float parentAlpha) { batch.draw(texture, getPosition().x - getWidth()/2, getPosition().y - getHeight()/2, this.getWidth()/2, this.getHeight()/2, getWidth(), getHeight(), 1, 1, getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false); super.draw(batch, parentAlpha);