浏览代码

tools: fix sprite z calculation

Daniele Bartolini 2 年之前
父节点
当前提交
45d7aefacf
共有 2 个文件被更改,包括 7 次插入6 次删除
  1. 1 0
      docs/changelog.rst
  2. 6 6
      samples/core/editors/level_editor/level_editor.lua

+ 1 - 0
docs/changelog.rst

@@ -19,6 +19,7 @@ Changelog
 * Fixed unit preview in the Resource Chooser.
 * The Console will now show a single line with a counter instead of spamming the view with duplicated entries.
 * Fixed Console's text color in dark/light mode.
+* Fixed mouse click in the Editor View not selecting the correct sprite in some circumnstances.
 
 0.49.0 --- 27 Nov 2023
 ----------------------

+ 6 - 6
samples/core/editors/level_editor/level_editor.lua

@@ -208,17 +208,17 @@ end
 function raycast(objects, pos, dir)
 	local object = nil
 	local nearest = math.huge
-	local layer = 0
-	local depth = 0
+	local sprite_z = 0
 
 	for k, v in pairs(objects) do
 		local t, l, d = v:raycast(pos, dir)
 		if t ~= -1.0 then
-			-- If sprite
+			-- If intersection.
 			if l and d then
-				if l >= layer and d >= depth then
-					layer = l
-					depth = d
+				-- If sprite.
+				local new_z = math.pow(2, 32)*l + d
+				if new_z >= sprite_z then
+					sprite_z = new_z
 					nearest = t
 					object = v
 				end