DEKI/ENGINE 文档
手册 API 参考
deki-tiledmapeditor-integration 0.40.1
Deki 包参考
deki-tiledmapeditor-integration

Tiled 地图编辑器集成。将 .tmj 文件放进项目,编辑器会将其烘焙为可流式读取的二进制瓦片地图。

仓库:github.com/dekiengine/deki-tiledmapeditor-integration · 最新版本:0.40.0 · 需要引擎 0.40.0 或更高版本 · 依赖:deki-2d, deki-rendering

使用 DekiEditor --packages-add deki-tiledmapeditor-integration <project> 或通过包管理器安装。引擎自身的组件和 C++ API 见 Deki 文档。

在编辑器中显示为 **Tiled Map Editor Integration**。

组件

组件 类别 说明
TilemapColliderComponent 瓦片地图 提供瓦片地图图层中每个图块的碰撞形状,供查询使用。
TilemapComponent 瓦片地图 绘制 Tiled 地图,在相机周围流式加载区块。
TilemapObjectSpawner 瓦片地图 场景加载时,根据 Tiled 地图的对象图层生成对象。

功能开关

可以从构建中去掉的部分。带有 define 的功能通过该 define 开关,其余的随其组件一起被剥离。

功能 define 默认值
Tilemap Rendering DEKI_FEATURE_TILEMAP_RENDER 开
Tilemap Collision DEKI_FEATURE_TILEMAP_COLLISION 开
Object Layers DEKI_FEATURE_TILEMAP_OBJECTS 开

组件参考

TilemapColliderComponent

提供瓦片地图图层中每个图块的碰撞形状,供查询使用。

检视器中的名称:瓦片地图碰撞体组件 · 类别:瓦片地图 · 类型:DekiTiledMap::TilemapColliderComponent

属性 类型 默认值 约束 说明
tilemap AssetRef (Tilemap) "" 其图块将成为实体的地图。
collisionLayer int32 0 地图中存放碰撞图块的图层。该图层上有图块的格子是实体,空格子则不是。
loopX bool false 在水平方向重复碰撞,以匹配循环的地图。
wrapPeriodX int32 0 loopX 允许时显示 水平方向一次重复的宽度,以图块为单位。0 表示使用地图自身的宽度。
loopY bool false 在垂直方向重复碰撞。
wrapPeriodY int32 0 loopY 允许时显示 垂直方向一次重复的高度,以图块为单位。0 表示使用地图自身的高度。

TilemapComponent

绘制 Tiled 地图,在相机周围流式加载区块。

检视器中的名称:瓦片地图组件 · 类别:瓦片地图 · 类型:DekiTiledMap::TilemapComponent

属性 类型 默认值 约束 说明
tilemap AssetRef (Tilemap) "" 从 Tiled 导出的地图。
visibleLayerMask int32 2147483647 要绘制地图的哪些图层,每个图层一位。所有位都置位时绘制全部图层。
chunkPadding int32 1 在屏幕边缘之外保持加载和绘制的区块数。留一点边距可以避免滚动时图块在边缘突然出现。
chunkCacheKiB int32 256 16 到 262144 此地图可用于保存已解码区块的内存量,单位为 KiB。超出预算时,最久未绘制的区块会被丢弃,再次需要时从存储中重新读取。因此设得太小的表现是滚动时卡顿,而不是内容缺失。ESP32 适合用 256;桌面平台可以用得多得多。
tintColor Color "#FFFFFFFF" 与每个图块相乘。白色则保持地图不变。
pixelsPerMeter float 16 1 到 256 地图上多少像素算作一米。地图正是靠它与场景中的其他内容对齐。
loopX bool false 在水平方向重复地图,滚动越过边缘时会绕回另一侧。
wrapPeriodX int32 0 loopX 允许时显示 水平方向一次重复的宽度,以图块为单位。0 表示使用地图自身的宽度。
loopY bool false 在垂直方向重复地图。
wrapPeriodY int32 0 loopY 允许时显示 垂直方向一次重复的高度,以图块为单位。0 表示使用地图自身的高度。

从 RendererComponent 继承 sortingOrder, ignoreClip, pixelSnap, alphaMode。

TilemapObjectSpawner

场景加载时,根据 Tiled 地图的对象图层生成对象。

检视器中的名称:瓦片地图对象生成器 · 类别:瓦片地图 · 类型:DekiTiledMap::TilemapObjectSpawner

属性 类型 默认值 约束 说明
tilemap AssetRef (Tilemap) "" 读取其对象图层的地图。在 Tiled 中放置的每个对象都会成为场景中的对象。
pixelsPerMeter float 16 1 到 256 地图上多少像素算作一米,使生成的对象落在 Tiled 中放置的位置。
sortBase int32 0 站在世界地平线(Y 0)上的图块对象的排序顺序。
sortPerMeter int32 0 图块对象的点每低一米,其排序顺序增加多少。大于 0 时,屏幕上位置越低的绘制在越上层,角色就能走到物体后面。设为每米像素数时,每个像素行对应一个顺序,与 Tiled 编辑器的对象叠放方式相同。为 0 时,所有图块对象都使用排序基准。

更新日志

更新日志为英文。

0.40.0

Fixed

  • A map under a camera that is not a number, or very far out, draws nothing. Its chunk range wrapped round and Tilemap::QueryVisibleChunks read past the end of its index, which crashed. A range with its ends the wrong way round now returns no chunks.

Changed

  • minEngine 0.40.0: built against engine 0.40.0. A build of this package from before does not load and is rebuilt.
  • The view copy works with a Pixel Perfect camera on screen pixels. A map drawn at 2x or more is still drawn from its copy when the camera's Pixel Grid is Screen, and scrolls a screen pixel at a time.

Added

  • The view copy works on ARGB8888 screens and at 2x, 3x... The copy a map is drawn into once, and copied from while the camera scrolls, was only made for RGB565 screens at 1:1, so a map on an ARGB8888 screen, or drawn larger under Pixel Perfect, was drawn tile by tile every frame. On ARGB8888 it is kept in the screen's format and copied row by row, where the map is the first thing drawn; under Pixel Perfect at a whole scale its tiles land on the same art-pixel grid as on screen. Nothing to set, and the same pixels: frames rendered both ways match. On the Anbernic RG40XX H (640x480, a four-layer isometric farm at 2x) the map went from 13 ms a frame to 2.6. The log says once when a map is drawn from a copy.
  • The map's render pass names itself "Tilemap" in the profiler's breakdown by object (RenderPass::Name).
  • Isometric maps. Set the map's orientation to Isometric in Tiled and it draws as diamonds, back to front across chunks, with tall tiles standing on their squares. Only chunks in view are loaded. Collision and spawned objects follow the same layout.
  • Tile objects placed in Tiled now appear. TilemapObjectSpawner gives each one a sprite of its tile, standing where Tiled draws it, with its flips, size and rotation. Sort Base and Sort Per Meter set its Sorting Order from where its point stands, so what stands lower on the screen can draw on top. A Tile Offset moves the picture without changing the order.
  • Tilemap::FindProperty, which finds one of an object's custom properties by name.
  • Tilesets with a margin or spacing. These were read as if they had none, which showed the wrong part of the image.
  • A tileset's Tile Offset and Object Alignment.
  • Group layers. Their layers used to be left out.
  • A layer's opacity, tint, offset and parallax, and a group's, drawn as in Tiled. An object layer's opacity, tint and offset apply to its objects.
  • Image layers, with their repeat across and down.
  • Animated tiles play, in tile layers and as tile objects, on one clock as in Tiled.
  • Tile and image layers above an object layer draw above its objects, as Tiled stacks them: the spawner draws them from components of their own.
  • Staggered and hexagonal maps, with either stagger axis and index and a hex side length, laid out and drawn in Tiled's order. Collision, spawned objects and Tilemap::PixelsToTile follow the same layout; Tilemap::Stagger() gives the grid.
  • A tileset's Tile Render Size set to Map Grid Size, with Fill Mode Stretch or Preserve Aspect Fit: its tiles are drawn at the map's tile size in tile layers.
  • Layer blend modes (Add, Multiply, Screen, Overlay, Darken, Lighten, Color Dodge, Color Burn, Hard Light, Soft Light, Difference, Exclusion) on tile and image layers, a group's too, blended as Tiled blends them. A blended layer costs two extra draws and a blend for each of its tiles. An object layer's blend mode is not drawn, and baking says so.
  • An object layer's parallax: its spawned objects go in an object named after the layer, which moves with the view before each frame as Tiled moves the layer.

Changed

  • A map that scrolls with the camera works out its copy once a frame. A frame redrawn in parts asked the map to draw once for each part, and each time the map found its layers, tilesets, box and copy again; now the frame's first part records what it found and the others only copy their pixels. With 16 sprites moving over the map on a LilyGO T-Deck that was about 15 parts a frame.- Tile layers draw faster, with the same pixels. Each tile gets the runs a sprite gets: its rows' transparent runs are skipped unread and its runs of one colour are filled. Only the cells that can reach the frame (or the strip being drawn) are walked. The tables they need live in external memory, so a board's internal RAM stays for its display and frame. On a LilyGO T-Deck at 320x240, a whole frame of an isometric map went from 34 to 24 ms, a staggered one from 38 to 25 ms and the "Your first game" farm from 38 to 33 ms. A layer with a blend mode draws in about half the time it first did. With the project's redrawChanges on, a map follows a camera that scrolls by whole pixels: only the edge it uncovers is drawn, and the same three maps hold 60 fps (16.6 ms, the display's own rate). That needs the map at the project's pixels per meter, on whole pixels, with parallax 1 and whole layer offsets; any other map redraws the whole frame as before. A layer walks only the cells its own tiles can reach the drawn area from, so a map's tall building tiles no longer widen the walk of its ground (the guide's farm: about 5200 cells walked a frame down to 900), and chunks asked for once in a frame are not asked for again by its later parts.
  • A map that scrolls with the camera keeps a copy of its pixels. Each group of layers a map draws together is kept, as drawn, in a buffer a margin larger than the view, in external memory. While the camera moves by whole pixels a frame, or each part redrawn of one, copies the map from there instead of drawing every layer's tiles again, and only what comes into view is drawn, a band at a time, at most one band piece a frame. Where the map is the first thing drawn, the copy holds it over the clear colour and the clear is skipped. The pixels are the ones drawing gives, checked pixel for pixel against drawing on a LilyGO T-Deck over every bench map. On the T-Deck the "Your first game" farm went from 31.7 to about 22.5 ms a frame with the camera following the farmer, and from 53.6 to 34.5 ms with 16 villagers walking. A layer group is drawn as before, every frame, when it has a tint, opacity, blend mode or parallax, animated tiles, tiles with partly see-through pixels, or a map scaled from its pixels per meter, in frames drawn in strips, on a GPU or not in RGB565, with the camera between pixels, and when there is no memory for the copy (about 190 KB at 320x240). A map draws nothing in the parts of a frame away from all its tiles.
  • An isometric map used to be drawn as a square grid and now draws correctly. One baked before this keeps the old layout until its .tmj is saved again.
  • Object positions and sizes keep Tiled's fractions (DTilemapObject::x, y, width and height are floats). They were rounded down to whole pixels, so an object at 10.5 now lands half a pixel further on. Maps are baked as file version 3; versions 1 and 2 still load, as whole pixels.
  • Objects spawned from a Tiled map keep the rotation drawn in Tiled, now that the engine draws positive rotation counter-clockwise (deki-rendering).
  • On an isometric map, tiles wider than the grid line up with the left corner of their square, as in Tiled.
  • A layer hidden in Tiled is no longer drawn, and collision can still read it. It used to be drawn. Show the layer in Tiled to keep it on screen.
  • On a square map, tiles taller than the grid stand on the bottom of their cell, as in Tiled. They used to hang down from its top.
  • On a square map, spawned objects land where Tiled shows them: relative to the map's centre, with Y up. They used to be off by the map's size and upside down, so anything placed to make up for that needs moving back.
  • A tile object used to spawn as an empty object and now also has a sprite, unless it is hidden in Tiled.
  • A tileset baked before this keeps ignoring its margin and spacing until its .tsj is saved again.
  • Spawned objects go into an object named "<owner> objects" beside the spawner's object, not under it. Under an object that draws the map they were drawn with it, so a character could never walk behind them. Code that looked for them among the map object's children needs to look there.
  • A map baked before this draws without its layers' opacity, tint, offsets, parallax and image layers until its .tmj is saved again (file version 2).
  • Sort Per Meter orders are floored, so each step is one order around 0 too, where they used to be cut toward 0 and the two steps either side of 0 shared an order.

0.30.0

Changed

  • minEngine 0.30.0: built against engine 0.30.0. A build of this package from before does not load and is rebuilt.

Added

  • Tiles carry their tileset image's filter (QuadBlit::Source::filter), so a GPU draws them as its Filter says, each tile within its own texels.
  • Tiles carry their atlas's revision (QuadBlit::Source::revision), and each opaque tile copy one of its own, so a GPU drawing the 2D (deki-gl) uploads each tile once. The map pass says it writes nothing into the frame buffer itself (RenderPass::WritesBuffer).

更早的版本:CHANGELOG.md


由包的反射数据生成(引擎 0.40.1)。属性名就是场景文件中使用的键。重命名后会保留别名(兼容性)。