ajout des textures d'annimation

This commit is contained in:
Damien 2021-05-14 10:33:03 +02:00
parent 19881f9ae5
commit 58eb1f7136
7 changed files with 32 additions and 18 deletions

View file

Before

Width:  |  Height:  |  Size: 783 B

After

Width:  |  Height:  |  Size: 783 B

BIN
core/assets/arrow0-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

BIN
core/assets/arrow0-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

BIN
core/assets/arrow0-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

View file

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

View file

Before

Width:  |  Height:  |  Size: 136 B

After

Width:  |  Height:  |  Size: 136 B

View file

@ -1,5 +1,7 @@
package sagittarius.model; package sagittarius.model;
import java.util.ArrayList;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
@ -28,7 +30,7 @@ public class Arrow extends EntityQuad {
private Planet crash; private Planet crash;
private Vector2 offset; private Vector2 offset;
private Texture texture; private ArrayList<Texture> texture;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
@ -49,24 +51,35 @@ public class Arrow extends EntityQuad {
this.landed = false; this.landed = false;
if (!preview) { if (!preview) {
Pixmap pm = new Pixmap(new FileHandle("core/assets/arrow" + MathUtils.random(2) + ".png")); texture = new ArrayList<>();
pm.setBlending(Pixmap.Blending.None); String path = "core/assets/arrow" + MathUtils.random(0);
for (int x = 0; x < pm.getWidth(); x++) {
for (int y = 0; y < pm.getHeight(); y++) { int i = 0;
while (true) {
Color pc = new Color(); try {
Color.rgba8888ToColor(pc, pm.getPixel(x, y)); Pixmap pm = new Pixmap(new FileHandle(path + "-" + i + ".png"));
pm.setBlending(Pixmap.Blending.None);
if (pc.r == 1 && pc.g == 1 && pc.b == 1) { for (int x = 0; x < pm.getWidth(); x++) {
pc.r = getColor().r; for (int y = 0; y < pm.getHeight(); y++) {
pc.g = getColor().g;
pc.b = getColor().b; Color pc = new Color();
Color.rgba8888ToColor(pc, pm.getPixel(x, y));
if (pc.r == 1 && pc.g == 1 && pc.b == 1) {
pc.r = getColor().r;
pc.g = getColor().g;
pc.b = getColor().b;
}
pm.drawPixel(x, y, Color.rgba8888(pc));
}
} }
texture.add(new Texture(pm));
pm.drawPixel(x, y, Color.rgba8888(pc)); i++;
} catch (com.badlogic.gdx.utils.GdxRuntimeException e) {
break;
} }
} }
texture = new Texture(pm);
} }
} }
@ -108,8 +121,9 @@ public class Arrow extends EntityQuad {
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
batch.draw(texture, getPosition().x - getOriginX(), getPosition().y - getWidth()/2, getOriginX(), getWidth()/2, getWidth(), getWidth(), int i = (int) (TTL * 3) % 4;
1, 1, getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false); batch.draw(texture.get(i), getPosition().x - getOriginX(), getPosition().y - getWidth()/2, getOriginX(), getWidth()/2, getWidth(), getWidth(),
1, 1, getRotation(), 0, 0, texture.get(i).getWidth(), texture.get(i).getHeight(), false, false);
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
} }