Skip to content

Commit

Permalink
fix: The tile building process will now shift cells if a given tile's…
Browse files Browse the repository at this point in the history
… offset reached or exceeds 1 in any direction brought on by a rule building multiple tiles. This fixed some render order problems
  • Loading branch information
Cammin committed Jul 22, 2024
1 parent be50841 commit 4346541
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Unity.Collections;
using System;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;

Expand Down Expand Up @@ -67,6 +68,16 @@ public void Execute(int i)
offset.x = pxOffsetX / (float)LayerGridSize;
offset.y = -pxOffsetY / (float)LayerGridSize;

//Rules can have multiple tiles built (like a 2x2 of art), but they all occupy the same coordId despite being located full cell(s) away!
//this results in offsets that can exceed 1 or -1, which at that point, should occupy the next cell over.
//not only is it easier to track down the tile in the editor, but it renders in a better z order with other tiles in that other cell.
int cellShiftX = offset.x > 0 ? (int)Math.Floor(offset.x) : (int)Math.Ceiling(offset.x);
int cellShiftY = offset.y > 0 ? (int)Math.Floor(offset.y) : (int)Math.Ceiling(offset.y);
cX += cellShiftX;
cY -= cellShiftY;
offset.x -= cellShiftX;
offset.y -= cellShiftY;

bool flipX = (input.Flip & 1) == 1;
bool flipY = (input.Flip & 2) == 2;

Expand Down
1 change: 1 addition & 0 deletions Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public TilemapTilesBuilder(Tilemap map, int capacity)
_depth = new Dictionary<Vector3Int, int>(10);
}

/// <param name="cell">Z is always 0</param>
public int GetNextCellZ(Vector3Int cell)
{
if (!_depth.ContainsKey(cell))
Expand Down

0 comments on commit 4346541

Please sign in to comment.