Hi,
I’m using the defold build in camera component and am setting orthographic to true and using a zoom value of 2.
This is what my game looks like when building in defold editor:
But when I build my game to android this is what it looks like:
Which is basically the zoom not applied and a zoom value of 1. On Android the zoom is not changing to the value set by me, I even tried by setting the value via script:
self.camera_url = msg.url(nil, "camera", "camera")
go.set(self.camera_url, "orthographic_zoom", 2)
But that also did not help.
adb logcat does not show any errors.
And idea what I can do to fix this and what might be the reason?
Thanks
Update:
so apparently the zoom is fine, as I added the following debugs:
self.camera_url = msg.url(nil, "camera", "camera")
local old_zoom = go.get(self.camera_url, "orthographic_zoom")
print("Old zoom:", old_zoom)
go.set(self.camera_url, "orthographic_zoom", 2)
local new_zoom = go.get(self.camera_url, "orthographic_zoom")
print("New zoom:", new_zoom)
and got:
05-12 09:28:13.311 2916 3071 I defold : INFO:ENGINE: Initialised sound device 'default'
05-12 09:28:13.585 2916 3071 W defold : WARNING:INPUT: No gamepad map found for gamepad 0 (Virtual). The raw gamepad map will be used.
05-12 09:28:13.704 2916 3071 D defold : DEBUG:SCRIPT: Old zoom: 2
05-12 09:28:13.704 2916 3071 D defold : DEBUG:SCRIPT: New zoom: 2
So the zoom value is fine, then why does it look like this on device?
What’s the resolution of your Android device? I bet it is quite high and with a fixed zoom of 2 it is still quite small. Shouldn’t you be checking the ratio between the width or height you have in game.project and the width or height you have on the device (use window.get_size()) and pick a zoom value based on that?
my device resolution is 1080 x 1920. Yes that looks like the approach to take I think, I was under the impression that the camera module would do that for me.
Coming from Unity, thats how it works there 
Does orthographic camera asset handle this by itself or do I have to write custom code for that as well? Just to try if it will work, I installed the orthographic camera asset and set the zoom value to 2.
It behaves in a similar way, looks ok on my laptop, but exactly how it was previously shown on device, ie zoomed out.
I think I may have found a solution using your orthographic camera asset.
So, I see that in the new version you have auto_zoom to perform these exact calculations, I let it calculate the auto_zoom based on my device resolution and since I want my game to appear at a zoom level of 2, because thats how I designed all the levels, I multiply the auto_zoom value with what I want
local auto_zoom = go.get("/camera#script", "zoom")
print("Auto zoom: " .. auto_zoom)
local artistic_zoom = 2.2
print("Artistic zoom: " .. artistic_zoom)
go.set("/camera#script", "automatic_zoom", false)
-- Apply the new zoom
go.set("/camera#script", "zoom", artistic_zoom)
print(go.get("/camera#script", "zoom"))
Before applying the zoom I disable automatic zoom.
This is working so far, would appreciate your comment on this if this is the correct way of doing this or if Im wrong in this implementation.
On editor, auto_zoom value is 0.9 and final zoom becomes 2.04.
On device, auto_zoom is 2 and final zoom becomes 4.4
The final look appears to be consistent between the two so far 
Ortho camera module may require an update(not sure, I’m not using it) to use the newly introduced display scale.
Zoom calculation is generally like this:
local zoom = math.min(M.window_width / M.game_width, M.window_height / M.game_height) / window.get_display_scale()
But this all may depend on how you want to handle your game scene.
3 Likes