proper sprite flip draw

This commit is contained in:
minjaesong
2017-07-02 00:45:57 +09:00
parent 4a54c87826
commit c8c1bdf836

View File

@@ -95,6 +95,31 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) {
val region = textureRegion.get(currentRow, currentFrame) val region = textureRegion.get(currentRow, currentFrame)
batch.color = colorFilter batch.color = colorFilter
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, batch.draw(region,
Math.round(posX).toFloat(), Math.round(posX).toFloat(),
FastMath.floor(posY).toFloat(), FastMath.floor(posY).toFloat(),
@@ -103,6 +128,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) {
) )
} }
} }
}
fun switchRow(newRow: Int) { fun switchRow(newRow: Int) {
currentRow = newRow % nRows currentRow = newRow % nRows