From 3d65d76c16081b5a13b8cdbfb9688b3fbebf96f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 23 Nov 2018 17:00:14 +0100 Subject: FramedSprite : add static trim and offset --- core/src/ch/asynk/gdx/boardgame/FramedSprite.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/ch/asynk/gdx/boardgame/FramedSprite.java b/core/src/ch/asynk/gdx/boardgame/FramedSprite.java index b09a3af..2f41afe 100644 --- a/core/src/ch/asynk/gdx/boardgame/FramedSprite.java +++ b/core/src/ch/asynk/gdx/boardgame/FramedSprite.java @@ -6,6 +6,9 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; public class FramedSprite implements Drawable, Positionable { + public static int trim = 2; + public static int offset = 0; + private TextureRegion[][] frames; private TextureRegion frame; public final int rows; @@ -23,6 +26,22 @@ public class FramedSprite implements Drawable, Positionable this.x = 0; this.y = 0; this.a = 0; + + if (trim > 0 || offset > 0) { + for (int r = 0; r < rows; r++) { + for (int c = 0; c < cols; c++) { + TextureRegion f = frames[r][c]; + if (offset > 0 ){ + f.setRegionX(f.getRegionX() + offset); + f.setRegionY(f.getRegionY() + offset); + } + if (trim > 0) { + f.setRegionWidth(f.getRegionWidth() - trim); + f.setRegionHeight(f.getRegionHeight() - trim); + } + } + } + } } public FramedSprite(FramedSprite other) -- cgit v1.1-2-g2b99