Skip to content

Commit

Permalink
Make rendering of background color optional (#5)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jobe-m authored Sep 12, 2024
1 parent c590319 commit a929885
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -165,18 +166,20 @@ 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 }
}

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)
}
Expand Down

0 comments on commit a929885

Please sign in to comment.