[SOLVED] What settings to use for defold-orthographic (britzl) to scale camera with screen size

I’m struggling to figure out what settings to use for orthographic addon orthographic to scale zoom based on screen size. Anyone can help? I cant edit zoom when i set it to automatic zoom.


If you switch from automatic to manual zoom you can calculate an appropriate zoom value based on the ratio between window dimensions set in game.project and the actual window/screen dimensions of the device. Here’s an example of this calculation and how it is used with the built-in camera component (you can use the same calculation for the Orthographic camera module):

2 Likes

Thanks this worked for me. I just changed the zoom on orthographic camera script. Changed orthographic_zoomtozoom property

local DISPLAY_WIDTH = sys.get_config_int("display.width")
local DISPLAY_HEIGHT = sys.get_config_int("display.height")

function init(self)
	local initial_zoom = go.get("/camera#script", "zoom")
	local display_scale = window.get_display_scale()
	window.set_listener(function(self, event, data)
		if event == window.WINDOW_EVENT_RESIZED then
			local window_width = data.width
			local window_height = data.height
			local design_width = DISPLAY_WIDTH / initial_zoom
			local design_height = DISPLAY_HEIGHT / initial_zoom

			-- with max zoom your initial design dimensions will fill and expand beyond screen bounds
			local zoom = math.max(window_width / design_width, window_height / design_height) / display_scale

			-- with min zoom your initial design dimensions will shrink and be contained within screen bounds
			--local zoom = math.min(window_width / design_width, window_height / design_height) / display_scale

			go.set("/camera#script", "zoom", zoom)
		end
	end)
end
1 Like