diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-01-02 12:05:18 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-01-02 12:05:18 +0100 |
commit | a97d1970b435f5a9de5ba9fcec48619140a0ad29 (patch) | |
tree | e01429a684e58e4018f8bb96a2919c04529bc241 /core | |
parent | d07be94ba960a71174fa178879396fde491b7f7a (diff) | |
download | RustAndDust-a97d1970b435f5a9de5ba9fcec48619140a0ad29.zip RustAndDust-a97d1970b435f5a9de5ba9fcec48619140a0ad29.tar.gz |
remove engine/gfx/Image: use Sprite instead
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/HeadedPawn.java | 14 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Pawn.java | 29 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/gfx/Image.java | 63 |
3 files changed, 22 insertions, 84 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/HeadedPawn.java b/core/src/ch/asynk/tankontank/engine/HeadedPawn.java index d237e88..7da5b8b 100644 --- a/core/src/ch/asynk/tankontank/engine/HeadedPawn.java +++ b/core/src/ch/asynk/tankontank/engine/HeadedPawn.java @@ -1,23 +1,22 @@ package ch.asynk.tankontank.engine; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import ch.asynk.tankontank.engine.gfx.Image; - import com.badlogic.gdx.math.Vector3; public abstract class HeadedPawn extends Pawn { - private Image head; + private Sprite head; protected Orientation orientation; public HeadedPawn(Faction faction, String pawn, String head, TextureAtlas pawns, TextureAtlas overlays) { super(faction, pawn, pawns, overlays); - this.head = new Image(pawns.findRegion(head)); + this.head = new Sprite(pawns.findRegion(head)); this.orientation = Orientation.KEEP; this.descr += " " + orientation; } @@ -26,7 +25,6 @@ public abstract class HeadedPawn extends Pawn public void dispose() { super.dispose(); - head.dispose(); } @Override @@ -54,7 +52,7 @@ public abstract class HeadedPawn extends Pawn super.setPosition(x, y); float cx = x + (getWidth() / 2f); float cy = y + (getHeight() / 2f); - head.centerOn(cx, cy); + head.setPosition((cx - (head.getWidth() / 2f)), (cy - (head.getHeight() / 2f))); } @Override @@ -82,7 +80,9 @@ public abstract class HeadedPawn extends Pawn @Override public void drawDebug(ShapeRenderer debugShapes) { - head.drawDebug(debugShapes); + float w = head.getWidth(); + float h = head.getHeight(); + debugShapes.rect(head.getX(), head.getY(), (w / 2f), (h / 2f), w, h, head.getScaleX(), head.getScaleY(), head.getRotation()); super.drawDebug(debugShapes); } } diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 0808f86..d3359ef 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -5,6 +5,7 @@ import java.util.Iterator; import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; @@ -12,7 +13,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; -import ch.asynk.tankontank.engine.gfx.Image; import ch.asynk.tankontank.engine.gfx.Moveable; import ch.asynk.tankontank.engine.gfx.StackedImages; import ch.asynk.tankontank.engine.gfx.animations.MoveToAnimation; @@ -99,7 +99,7 @@ public abstract class Pawn implements Moveable, Disposable private Tile prevTile; protected Faction faction; protected String descr; - private Image image; + private Sprite sprite; private StackedImages overlays; public Engagement engagement = new Engagement(); public Movement movement= new Movement(); @@ -142,7 +142,7 @@ public abstract class Pawn implements Moveable, Disposable this(); this.faction = faction; this.descr = descr; - this.image = new Image(pawns.findRegion(name)); + this.sprite = new Sprite(pawns.findRegion(name)); this.overlays = new StackedImages(overlays); } @@ -155,7 +155,6 @@ public abstract class Pawn implements Moveable, Disposable @Override public void dispose() { - image.dispose(); } @Override @@ -262,38 +261,38 @@ public abstract class Pawn implements Moveable, Disposable @Override public void setAlpha(float alpha) { - image.setAlpha(alpha); + sprite.setAlpha(alpha); overlays.setAlpha(alpha); } @Override public float getX() { - return image.getX(); + return sprite.getX(); } @Override public float getY() { - return image.getY(); + return sprite.getY(); } @Override public float getWidth() { - return image.getWidth(); + return sprite.getWidth(); } @Override public float getHeight() { - return image.getHeight(); + return sprite.getHeight(); } @Override public float getRotation() { - return image.getRotation(); + return sprite.getRotation(); } public Orientation getOrientation() @@ -315,7 +314,7 @@ public abstract class Pawn implements Moveable, Disposable public void setPosition(float x, float y) { position.set(x, y, 0f); - image.setPosition(x, y); + sprite.setPosition(x, y); float cx = x + (getWidth() / 2f); float cy = y + (getHeight() / 2f); overlays.centerOn(cx, cy); @@ -324,7 +323,7 @@ public abstract class Pawn implements Moveable, Disposable public void setRotation(float z) { position.z = z; - image.setRotation(z); + sprite.setRotation(z); overlays.setRotation(z); } @@ -383,14 +382,16 @@ public abstract class Pawn implements Moveable, Disposable @Override public void draw(Batch batch) { - image.draw(batch); + sprite.draw(batch); overlays.draw(batch); } @Override public void drawDebug(ShapeRenderer debugShapes) { - image.drawDebug(debugShapes); + float w = sprite.getWidth(); + float h = sprite.getHeight(); + debugShapes.rect(sprite.getX(), sprite.getY(), (w / 2f), (h / 2f), w, h, sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation()); overlays.drawDebug(debugShapes); } } diff --git a/core/src/ch/asynk/tankontank/engine/gfx/Image.java b/core/src/ch/asynk/tankontank/engine/gfx/Image.java deleted file mode 100644 index a85cabf..0000000 --- a/core/src/ch/asynk/tankontank/engine/gfx/Image.java +++ /dev/null @@ -1,63 +0,0 @@ -package ch.asynk.tankontank.engine.gfx; - -import com.badlogic.gdx.utils.Disposable; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.Sprite; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; - -public class Image extends Sprite implements Drawable, Disposable -{ - private Texture texture; - - protected Image() - { - } - - public Image(Texture texture) - { - super(texture); - this.texture = texture; - } - - public Image(TextureRegion region) - { - super(region); - this.texture = null; - } - - @Override - public void dispose() - { - if (texture != null) texture.dispose(); - } - - public boolean hit(float x, float y) - { - return ((x >= getX()) && (y >= getY()) && (x <= (getX() + getWidth())) && (y <= (getY() + getHeight()))); - } - - public void setPosition(float x, float y, float r) - { - setPosition(x, y); - setRotation(r); - } - - public void centerOn(float cx, float cy) - { - setPosition((cx - (getWidth() / 2f)), (cy - (getHeight() / 2f))); - } - - @Override - public void draw(Batch batch) - { - super.draw(batch); - } - - @Override - public void drawDebug(ShapeRenderer shapes) - { - shapes.rect(getX(), getY(), (getWidth() / 2f), (getHeight() / 2f), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); - } -} |