Discord
Login
Community
DARK THEME

zoom camera

Do you know how I can add a zoom behavior when the "space" key is pressed using this code `initCamera = function() camera = object x = 0 y = 0 end end updateCamera = function() camera.x = clamp(player.x, -389, 389) camera.y = clamp(player.y, -389,389) end

clamp = function(value, lower_limit, upper_limit) local val = max(value, lower_limit) val = min(val, upper_limit) return val end`

the only way I know how is to use screen.setScale() the only downside is that you have to multiply every variable by the camera scale for stuff like collision to calculate properly.

if you're fine with that then;

if keyboard.SPACE then
  camera.scale += 0.03
end

draw = function()
 screen.setScale(camera.scale)
end

thanks I will try it

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community