How to zoom in to Game Object?

Hey guys!

Can anyone help me with figuring out how to zoom in to a game object, and then zoom out, back to the original display once an action is completed?

Thank you!

The easiest way to do this is to use RenderCam or Defold-Orthographic from the Asset Portal. RenderCam is easier to zoom with to be honest (I need to improve my camera).

If you want to do it yourself then you need to use a custom render script and manipulate the view projection.

3 Likes

If you decide to use Rendercam, here is a minimal script to animate zoom (you can’t animate it directly, unfortunately, but it’s still pretty simple).

Script (click to show)
local rendercam = require "rendercam.rendercam"

go.property("zoom", 1)
local out_zoom = 1
local in_zoom = 0.5
local zoom_time = 0.75


function init(self)
	msg.post(".", "acquire_input_focus")
	self.zooming = false
end

function update(self, dt)
	if self.zooming then
		rendercam.set_ortho_scale(self.zoom)
	end
end

function on_input(self, action_id, action)
	if action_id == hash("mouse click") then
		if action.pressed then
			self.zooming = true
			go.animate("#", "zoom", go.PLAYBACK_ONCE_FORWARD, in_zoom, go.EASING_INOUTCUBIC, zoom_time, 0, function() self.zooming = false end)
		elseif action.released then
			self.zooming = true
			go.animate("#", "zoom", go.PLAYBACK_ONCE_FORWARD, out_zoom, go.EASING_INOUTCUBIC, zoom_time, 0, function() self.zooming = false end)
		end
	end
end

And a tiny sample project using it:
Zoom in on object.zip (2.2 KB)

4 Likes

Thanks guys!

1 Like

I’ve just released a new version of my Orthographic Camera. It’s now possible to manipulate the zoom, bounds, deadzone and camera follow target using script properties. This makes it a lot easier to zoom in and out, for instance using go.animate().

8 Likes

Any chance of adding support for go.animate? :slight_smile: Just started using Rendercam and had gotten used to the “zoom” property of Ortho.

1 Like

Yup. I actually already did this, but it’s only on my “dev” branch, which is a bit of a mess right now. :confused: I think it was a breaking change, so I never merged it into the main branch. I’ll get to work on it.