Skip to content

Commit 6d3a720

Browse files
committed
Improved handling of window size changes
1 parent 307b9cd commit 6d3a720

File tree

4 files changed

+11
-27
lines changed

4 files changed

+11
-27
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ The Orthographic API provides a helper module to easily update the camera and se
9595
end
9696

9797
function update(self)
98-
render_helper.update()
99-
...
100-
10198
render_helper.set_world_view_projection()
10299
-- draw world
103100
...

orthographic/camera.lua

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,17 @@ function M.set_window_scaling_factor(scaling_factor)
144144
end
145145
end
146146

147-
--- Set the window size
148-
-- Call this from your render script to update the current window size
149-
-- The width and height can later be retrieved through the M.get_window_size()
150-
-- function. This is a convenience for use by custom projector functions
147+
--- Update the window size
151148
-- @param width Current window width
152149
-- @param height Current window height
153-
function M.set_window_size(width, height)
154-
assert(width, "You must provide window width")
155-
assert(height, "You must provide window height")
150+
local function update_window_size()
151+
local width, height = window.get_size()
152+
if width == 0 or height == 0 then
153+
return
154+
end
155+
if width == WINDOW_WIDTH and height == WINDOW_HEIGHT then
156+
return
157+
end
156158
WINDOW_WIDTH = width
157159
WINDOW_HEIGHT = height
158160

@@ -269,6 +271,8 @@ function M.update(camera_id, dt)
269271
return
270272
end
271273

274+
update_window_size()
275+
272276
local camera_world_pos = go.get_world_position(camera_id)
273277
local camera_world_to_local_diff = camera_world_pos - go.get_position(camera_id)
274278
local follow_enabled = go.get(camera.url, "follow")

orthographic/render/helper.lua

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,11 @@ local world_view = vmath.matrix4()
1515
local world_projection = vmath.matrix4()
1616
local screen_view = vmath.matrix4()
1717
local camera_offset = nil
18-
local window_width = nil
19-
local window_height = nil
2018

2119

2220
function M.init()
2321
end
2422

25-
26-
function M.update()
27-
local current_window_width = render.get_window_width()
28-
local current_window_height = render.get_window_height()
29-
if window_width ~= current_window_width or window_height ~= current_window_height then
30-
window_width = current_window_width
31-
window_height = current_window_height
32-
camera.set_window_size(current_window_width, current_window_height)
33-
end
34-
end
35-
36-
3723
function M.world_projection()
3824
return world_projection
3925
end

orthographic/render/orthographic.render_script

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ function init(self)
1919
end
2020

2121
function update(self)
22-
render_helper.update()
23-
24-
2522
-- clear color
2623
render.set_depth_mask(true)
2724
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})

0 commit comments

Comments
 (0)