Skip to main content

Tiled Layer Properties

Hs2d reads normal Tiled layer fields plus a small hs2d:* custom-property vocabulary. Put engine directives under hs2d:*; keep game-specific properties unprefixed or under your own prefix.

Properties are flattened by name. If the same custom property appears more than once on the same source, the later entry wins.

Property Value Rules

Hs2dLevel has helpers for common property types:

HelperAccepted values
getNumberProperty(source, name, fallback)Numbers, or decimal strings such as 12, -4, 0.5.
getStringProperty(source, name, fallback)Strings, or number/boolean values converted with String(value).
getBooleanProperty(source, name, fallback)Booleans, or exact strings true and false.

Color properties use parseHs2dColorProperty:

Tiled valueRuntime color
#RRGGBB0xRRGGBBff
#AARRGGBB0xRRGGBBAA
numberUsed as-is, already in Hs2d 0xRRGGBBAA form.

Invalid color strings are ignored and the relevant fallback is used.

Map Properties

PropertyTypeDefaultRuntime behavior
hs2d:clearColorcolor string or numberBuilder clearColor, then 0x000000ffWorld clear color. Also used as the fallback sky clear color.
Any other propertyanynonePreserved on level.properties for game code.

Use map properties for level-wide data such as music keys or difficulty only when runtime code reads them through Hs2dLevel.

Native Tiled Layer Fields

These are not custom properties, but Hs2d parses them on tile, image, object, and group layers:

Tiled fieldRuntime nameBehavior
parallaxxparallaxXMultiplied through group ancestry. Used by image parallax and decor defaults.
parallaxyparallaxYMultiplied through group ancestry. Used by image parallax and decor defaults.
offsetxoffsetXAdded through group ancestry. Used by image layer draw offsets.
offsetyoffsetYAdded through group ancestry. Used by image layer draw offsets.
visiblevisibleInherited through groups. Invisible layers are skipped by Hs2dWorldBuilder.
opacityopacityMultiplied through groups and preserved on parsed layers. The current builder paths do not apply opacity.
repeatxrepeatXParsed for image layers. Current parallax builder does not use horizontal repeat.
repeatyrepeatYParsed for image layers. Surface parallax uses it as repeatHeight; direct parallax does not.

Image Layer Properties

Image layers are built by Hs2dWorldBuilder.buildImageLayer. The default image role is parallax.

PropertyTypeDefaultApplies toBehavior
hs2d:assetstringlayer namesky, parallaxAsset-gate bitmap name. This must match the name passed to Hs2dAssetGate.add(name, uri), not necessarily the namespaced manifest key.
hs2d:rolestringparallaximage layersky builds a screen-fit sky layer. Any other value follows the parallax path.
hs2d:clearColorcolorworld clear colorskyClear color used by world.addSky.
hs2d:designHeightnumber0parallaxIf greater than zero and different from viewport height, the bitmap and pixel-space options are scaled once at build time.
hs2d:composestringsurfaceparallaxdirect creates a direct parallax layer. Other values create a surface parallax layer.
hs2d:scrollSlacknumber0direct, surface parallaxExtra strip slack for scroll coverage. Scaled by designHeight fit.
hs2d:driftXnumber0direct, surface parallaxHorizontal drift in pixels per second. Scaled by designHeight fit.
hs2d:anchorBottomWorldYnumberunsetdirect parallaxWorld-space Y line used to pin the strip bottom to the screen until the camera rises above it. Not scaled by designHeight.
hs2d:anchorWorldHeightnumberunsetdirect parallax with bottom anchorWorld-space band height. Scales the source vertically with camera zoom so its top remains world-aligned. Not scaled by designHeight.
hs2d:surfaceWidthnumberbitmap widthsurface parallaxCached parallax surface width. Scaled by designHeight fit.
hs2d:surfaceHeightnumberbitmap heightsurface parallaxCached parallax surface height. Scaled by designHeight fit.
hs2d:znumberbuilder layer ordersurface parallaxExplicit z order. Values below 0 are ignored.
hs2d:zoomScaleRationumber0surface parallaxZoom scale ratio passed to the parallax layer.
hs2d:minScalenumber1surface parallaxMinimum zoom-constrained scale.
hs2d:maxScalenumber1surface parallaxMaximum zoom-constrained scale.

Direct image layers are the low-overhead path for finished strip art: one clipped blit per frame, no intermediate surface. Surface parallax layers are appropriate when the layer needs a cached surface, vertical repeat, z control, or zoom constraints.

The bottom-anchor properties are useful for water, fog, or foreground bands that meet a fixed world line. Hosanario's water layer uses hs2d:anchorBottomWorldY=2176 and hs2d:anchorWorldHeight=120.

Example:

{
"type": "imagelayer",
"name": "clouds",
"image": "clouds-strip.png",
"parallaxx": 0.08,
"parallaxy": 0,
"offsety": 24,
"properties": [
{ "name": "hs2d:asset", "type": "string", "value": "clouds-strip" },
{ "name": "hs2d:designHeight", "type": "int", "value": 720 },
{ "name": "hs2d:compose", "type": "string", "value": "direct" },
{ "name": "hs2d:scrollSlack", "type": "int", "value": 1280 },
{ "name": "hs2d:driftX", "type": "int", "value": 7 }
]
}

Tile Layer Properties

Tile layer properties control which renderer is built.

PropertyTypeDefaultApplies toBehavior
hs2d:modestringautotile layerauto, dynamic, static, or cached. Invalid values fall back to auto.
hs2d:znumberorder * 10dynamic tile layerTile sprite z order.
hs2d:spriteLayerstringbuilder spriteLayerIddynamic tile layerHosting Hs2dSpriteLayer id. In ordinary builder use, this must equal the configured spriteLayerId; see Named Sprite Layers.
hs2d:poolPaddingnumber2dynamic/auto estimateExtra tile columns/rows around the visible window. Also affects auto-mode pool sizing.
hs2d:chunkWidthnumber512cached tile layerCached chunk surface width, unless tileLayerChunkSizes[layerId].width overrides it.
hs2d:chunkHeightnumber512cached tile layerCached chunk surface height, unless tileLayerChunkSizes[layerId].height overrides it.
hs2d:clearColorcolortransparent/implementation defaultstatic, cachedStatic uses it as clearColor; cached uses it as surfaceClearColor.
hs2d:viewportClearColorcolorimplementation defaultstaticViewport clear color for static tile layers.
hs2d:allowLargeWorldSurfacebooleanfalsestaticAllows a static whole-layer surface to exceed the normal guard. Use only for intentionally small-risk targets.

Mode behavior:

ModeBuilder path
autoEstimates worst-case dynamic pool from viewport, minScale, tile size, and poolPadding. If the estimate is over 4096, builds cached chunks; otherwise builds the dynamic tile layer.
dynamicForces the dynamic tile-layer branch.
staticBuilds one whole-layer cached surface. Does not require the default foreground sprite layer.
cachedBuilds cached chunks. Does not require the default foreground sprite layer.

Example:

{
"type": "tilelayer",
"name": "terrain",
"width": 228,
"height": 34,
"data": [0, 1, 2],
"properties": [
{ "name": "hs2d:mode", "type": "string", "value": "auto" },
{ "name": "hs2d:z", "type": "int", "value": 40 }
]
}

Object Group Properties

Object groups are built by role. The default object role is entities.

PropertyTypeDefaultApplies toBehavior
hs2d:rolestringentitiesobject groupdecor, entities, and zones are the verified roles. Unknown roles stay data-only.
hs2d:znumberorder * 10decor, entitiesDefault z for decor objects or entity groups. Entity binding zIndex overrides it.
hs2d:spriteLayerstringbuilder spriteLayerIddecor, entity groups without binding layerHosting sprite layer id. In ordinary builder use, this must equal the configured spriteLayerId; see Named Sprite Layers.
hs2d:cullPaddingXnumber512decorDefault horizontal decor culling slack.
hs2d:cullPaddingYnumber512decorDefault vertical decor culling slack.

Role behavior:

RoleBuilder behavior
decorConverts objects into parallax sprite items using per-object decor properties.
entitiesLooks up each object type in the code-side entities binding map and creates bound sprites.
zonesDoes not build render objects. Game code queries the objects from Hs2dLevel.
unknownDoes not build render objects. The objects remain queryable.

Decor Object Properties

Decor objects are read by Hs2dLevel.getParallaxSpriteSpecs.

| Property | Type | Default | Behavior | | --- | --- | --- | | frame | string | object name, then object type | Decor frame id. Builder maps this through decorFrames or uses it as the asset name. | | parallaxX | number | object-group parallaxX, then 1 | Per-object horizontal parallax multiplier. | | parallaxY | number | object-group parallaxY, then 1 | Per-object vertical parallax multiplier. | | zIndex | number | object-group hs2d:z, then order * 10 | Per-object z order. | | cullPaddingX | number | object-group hs2d:cullPaddingX, then 512 | Horizontal culling slack. | | cullPaddingY | number | object-group hs2d:cullPaddingY, then 512 | Vertical culling slack. |

Example:

{
"type": "objectgroup",
"name": "background-decals",
"properties": [{ "name": "hs2d:role", "type": "string", "value": "decor" }],
"objects": [{
"name": "moon",
"type": "decal",
"x": 179.12,
"y": 4915.2,
"properties": [
{ "name": "frame", "type": "string", "value": "moon" },
{ "name": "parallaxX", "type": "float", "value": 0.035 },
{ "name": "parallaxY", "type": "float", "value": 0.075 },
{ "name": "zIndex", "type": "int", "value": 12 },
{ "name": "cullPaddingX", "type": "int", "value": 720 },
{ "name": "cullPaddingY", "type": "int", "value": 520 }
]
}]
}

Entity Object Properties

The engine does not reserve hs2d:* properties for individual entity objects today. Entity object properties are game-owned data read by spawn callbacks and simulations.

Examples from the samples:

PropertyOwnerUse
variantvertical shooter, HosanarioSelects enemy frame/behavior.
healthvertical shooterInitial enemy health override.
axisHosanarioMoving platform axis.
orderHosanarioCheckpoint ordering.

Use level.getNumberProperty, level.getStringProperty, and level.getBooleanProperty in binding code so Tiled's property type choices do not leak into gameplay logic.

Named Sprite Layers

Hs2dWorldBuilder.fromLevel(...) creates a private world and lazily creates one default foreground Hs2dSpriteLayer. Its id is the spriteLayerId option, defaulting to hs2d-foreground.

In the normal builder path:

  • omit hs2d:spriteLayer and entity binding layer to use that default
  • or set them to the same id passed as spriteLayerId

The public builder options do not accept pre-created layers or an existing world, so a distinct named layer cannot be injected before fromLevel() resolves the map. Build the world imperatively when multiple independently configured sprite layers are required. The current source error suggesting that callers “add it before building” does not describe an available public builder path.

Zone Objects

Zones are ordinary Tiled objects in an object group with hs2d:role=zones. The builder skips them, and game code reads them by group and type.

Example:

{
"type": "objectgroup",
"name": "zones",
"properties": [{ "name": "hs2d:role", "type": "string", "value": "zones" }],
"objects": [
{ "name": "spawn", "type": "player-spawn", "x": 128, "y": 1856, "width": 64, "height": 64 },
{ "name": "pit-46", "type": "hazard", "x": 2944, "y": 2112, "width": 192, "height": 64 }
]
}

Do And Don't

Do:

  • use hs2d:* only for properties the builder understands
  • use native Tiled parallax fields for image/decor layer movement
  • set hs2d:asset when the asset-gate name differs from the layer name
  • use hs2d:compose=direct for simple strip backgrounds
  • leave gameplay tuning data as object properties read by code

Don't:

  • assume every parsed native Tiled field is applied by the builder
  • rely on image layer image as the asset key when hs2d:asset is set
  • put entity binding details such as sprite frames in Tiled
  • point hs2d:spriteLayer at an id other than the builder's configured spriteLayerId
  • use static tile mode for large worlds unless the surface size is known to be safe

Source Reference

SourceConfirms
../games/hosanna-ui/src/hosanna-game/hosanna2d/Hs2dWorldBuilder.tsAll verified hs2d:* builder properties, defaults, color parsing, tile mode selection, decor/entity/zones behavior.
../games/hosanna-ui/src/hosanna-game/hosanna2d/level/Hs2dLevel.tsProperty helper coercion, parallax sprite spec defaults, tile solidity, and object lookup.
../games/hosanna-ui/src/hosanna-game/hosanna2d/level/Hs2dTiledLevel.tsNative Tiled fields parsed on layers and group composition.
../games/hosanna-ui/src/hosanna-game/hosanna2d/Hs2dWorldBuilder.test.tsTested builder behavior for modes, chunk sizing, visibility skips, color parsing, decor asset failures, entity binding, and auto tile mode.
../hosanna-ui-game-samples-public/asset-bundles/hosanario/levels/level-1.jsonReal direct parallax, terrain, entities, and zones properties.
../hosanna-ui-game-samples-public/asset-bundles/native-shoot-em-up/levels/level-1.jsonReal sky, surface parallax, decor, and entity properties.
Talk to us