From ad9d8de86f6aae32fd935115a1175d0e8281de5a Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 2 Jul 2017 00:45:57 +0900 Subject: [PATCH] proper sprite flip draw --- .../spriteanimation/SpriteAnimation.kt | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/net/torvald/spriteanimation/SpriteAnimation.kt b/src/net/torvald/spriteanimation/SpriteAnimation.kt index 52ed9ec40..8c4af5477 100644 --- a/src/net/torvald/spriteanimation/SpriteAnimation.kt +++ b/src/net/torvald/spriteanimation/SpriteAnimation.kt @@ -95,12 +95,38 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) { val region = textureRegion.get(currentRow, currentFrame) batch.color = colorFilter - batch.draw(region, - Math.round(posX).toFloat(), - FastMath.floor(posY).toFloat(), - FastMath.floor(cellWidth * scale).toFloat(), - FastMath.floor(cellHeight * scale).toFloat() - ) + if (flipHorizontal && flipVertical) { + batch.draw(region, + Math.round(posX).toFloat() + (2f * parentActor.hitboxTranslateX * parentActor.scale.toFloat() + parentActor.hitbox.width.toFloat()), + FastMath.floor(posY).toFloat() + (2f * parentActor.hitboxTranslateY * parentActor.scale.toFloat() + parentActor.hitbox.height.toFloat()), + -FastMath.floor(cellWidth * scale).toFloat(), + -FastMath.floor(cellHeight * scale).toFloat() + ) + } + else if (flipHorizontal) { + batch.draw(region, + Math.round(posX).toFloat() + (2f * parentActor.hitboxTranslateX * parentActor.scale.toFloat() + parentActor.hitbox.width.toFloat()), + FastMath.floor(posY).toFloat(), + -FastMath.floor(cellWidth * scale).toFloat(), + FastMath.floor(cellHeight * scale).toFloat() + ) + } + else if (flipVertical) { + batch.draw(region, + Math.round(posX).toFloat(), + FastMath.floor(posY).toFloat() + (2f * parentActor.hitboxTranslateY * parentActor.scale.toFloat() + parentActor.hitbox.height.toFloat()), + FastMath.floor(cellWidth * scale).toFloat(), + -FastMath.floor(cellHeight * scale).toFloat() + ) + } + else { + batch.draw(region, + Math.round(posX).toFloat(), + FastMath.floor(posY).toFloat(), + FastMath.floor(cellWidth * scale).toFloat(), + FastMath.floor(cellHeight * scale).toFloat() + ) + } } }