Not sure if this helps, but I did this in order to make the camera properly view a specified rectangular area in the game, correcting for aspect ratio.
I guess you just need to run it every frame, or detect when a resize occurs. In my case, I just run it once on startup.
All of this code is in my custom render_script:
function init(self)
self.x = 0
self.y = 0
self.w = 1
self.h = 1
[...]
[...]
render.set_projection(vmath.matrix4_orthographic(self.x, self.x+self.w, self.y, self.y+self.h, -10, 10))
[...]
[code]function adjust_camera_after_tiles(self, rect)
-- Add some padding
local pad = 64
rect.x = rect.x - pad
rect.y = rect.y - pad
rect.w = rect.w + pad*2
rect.h = rect.h + pad*2
-- Get ratios
local ratio_screen = render.get_window_width()/render.get_window_height()
local ratio_tiles = rect.w/rect.h
-- Aspect ratio correction
if ratio_screen > ratio_tiles then
local mod = rect.h * ratio_screen;
rect.x = rect.x - (mod - rect.w) * 0.5
rect.w = mod
else
local mod = rect.w / ratio_screen;
rect.y = rect.y - (mod - rect.h) * 0.5
rect.h = mod
end
-- Send to level data
level_data.camera_rect = { x = rect.x, y = rect.y, w = rect.w, h = rect.h }
-- Save in this object
self.x = rect.x
self.y = rect.y
self.w = rect.w
self.h = rect.h
-- Save camera res
level_data.screen_res = { x = render.get_window_width(), y = render.get_window_height() }
end[/code]
But, again, this should really be automatic