Skip to content

Commit 549a2a8

Browse files
authored
Fix screen to world ortho example (#92)
1 parent 8d609fa commit 549a2a8

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

render/screen_to_world/example/bee.script

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ local function screen_to_world(x, y, z, camera_id)
77
local view = camera.get_view(camera_id)
88
local w, h = window.get_size()
99

10-
-- The window.get_size() function will return the scaled window size,
11-
-- ie taking into account display scaling (Retina screens on macOS for
12-
-- instance). We need to adjust for display scaling in our calculation.
13-
local scale = window.get_display_scale()
14-
w = w / scale
15-
h = h / scale
16-
1710
-- https://defold.com/manuals/camera/#converting-mouse-to-world-coordinates
1811
local inv = vmath.inv(projection * view)
1912
x = (2 * x / w) - 1
@@ -33,8 +26,8 @@ end
3326
function on_input(self, action_id, action)
3427
if action_id == hash("touch") and action.pressed then
3528
-- convert mouse/touch screen position to world position
36-
local worldx, worldy = screen_to_world(action.x, action.y, 0, "#camera")
29+
local worldx, worldy = screen_to_world(action.screen_x, action.screen_y, 0, "#camera")
3730
local world = vmath.vector3(worldx, worldy, 0)
38-
go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, world, go.EASING_LINEAR, 0.5, 0, moved_to_position) -- <8>
31+
go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, world, go.EASING_LINEAR, 0.5, 0)
3932
end
40-
end
33+
end

0 commit comments

Comments
 (0)