From a9298851398b4006238e9e14d98e847f751c635e Mon Sep 17 00:00:00 2001 From: Marko Koschak Date: Thu, 12 Sep 2024 08:01:06 +0200 Subject: [PATCH] Make rendering of background color optional (#5) LDtk level view always renders the background color as a solidRect. But sometimes it is needed that a level map view is opaque because e.g. some other background objects should be visible. This commit adds an option to disable rendering of the soldRect for the background color. --- .../kotlin/korlibs/korge/ldtk/view/LDTKView.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/korge-ldtk/src/commonMain/kotlin/korlibs/korge/ldtk/view/LDTKView.kt b/korge-ldtk/src/commonMain/kotlin/korlibs/korge/ldtk/view/LDTKView.kt index 623c492..51530ec 100644 --- a/korge-ldtk/src/commonMain/kotlin/korlibs/korge/ldtk/view/LDTKView.kt +++ b/korge-ldtk/src/commonMain/kotlin/korlibs/korge/ldtk/view/LDTKView.kt @@ -154,7 +154,8 @@ class LDTKLayerView( class LDTKLevelView( val level: LDTKLevel, - var showCollisions: Boolean = false + private var showCollisions: Boolean = false, + private var showBackground: Boolean = true ) : Container() { private val ldtk get() = level.ldtk private val world get() = level.world @@ -165,6 +166,7 @@ class LDTKLevelView( val bgLayer = solidRect(blevel.pxWid, blevel.pxHei, Colors[blevel.levelBgColor ?: ldtk.defaultLevelBgColor]).also { it.name = "background" + it.visible = showBackground } val layerViews = level.layers.asReversed().map { layer -> LDTKLayerView(layer, showCollisions).addTo(this) } val layerViewsByName = layerViews.associateBy { it.layer.identifier } @@ -172,11 +174,12 @@ class LDTKLevelView( class LDTKWorldView( val world: LDTKWorld, - var showCollisions: Boolean = false + showCollisions: Boolean = false, + showBackground: Boolean = true ) : Container() { init { for (level in world.levels) { - LDTKLevelView(level, showCollisions) + LDTKLevelView(level, showCollisions, showBackground) .addTo(this) .xy(level.level.worldX, level.level.worldY) }