I’m using a camera on my platformer game but I would like to put the camera closer to the player (so zoom in a bit) but I don’t understand how to use Cameras and renders
Someone can explain a bit more than the defold doc please ?
Which files needed ? And how to set them ?
I haven’t actually tried this myself, but after reading the camera documentation it seems as the only thing you have to do is to add the camera component to a game object and let it acquire camera focus. Once the camera is added and has focus it will post it’s current view projection to the render script.
This should be described clearly in the camera documentation but if any part of the documentation is unclear then please let us know where you get stuck and maybe share your script file where you acquire camera focus and post a screenshot of your collection with the camera game object.
Zooming in and out should be as easy as modifying the z position of the game object the camera is attached to.
Actually, the default render script does orthogonal rendering so the Z position has no effect. The camera and rendering documentation explains how this is set up.
I tried but it doesn’t work I have a script error on set_projection function
and lerp function.
I’ve copied the default.render et default.render_script to another place and renamed them as custom.*
Then I’ve changed the render in my game.project to custom.render.
My project contains 3 screens : 1 Main menu, 1 Levels menu and 1 Game screen (where the player plays )
My camera is only present on my Game screen and follows the player
Here’s my camera.script:
screen_width = tonumber(sys.get_config("display.width"))
screen_height = tonumber(sys.get_config("display.height"))
function init()
msg.post("#camera", "acquire_camera_focus")
end
function on_message(self, message_id, message, sender)
if message_id == hash("follow") then
local pos_x = message.position.x - (screen_width/ 2)
if pos_x <= 0 then
pos_x = 0
elseif pos_x >= screen_width then
pos_x = screen_width
end
local pos_y = message.position.y - (screen_height / 2)
if pos_y <= 0 then
pos_y = 0
elseif pos_y >= screen_height then
pos_y = screen_height
end
go.set_position(vmath.vector3(pos_x, pos_y, 0))
end
end
My player.script just send a message “follow” to the camera.script to make it follow.
To “zoom” an orthogonal camera you need to change the left, right, top and bottom values instead of the actual Z-position. Try playing around with the projection matrix like this:
Thanks a lot Sven it works. I changed some of your value of course and now it’s fine but one more thing, now my graphics are a bit “blurred” it’s a 2D game I make, with 128x128px tilemap, is there a way to avoid this blur thing ?
I think what you encounter with blurred graphics is due to texture filtering, linear vs nearest, have a look at this post: Low resolution pixel art game
Oh ok I will you msg.post("@render",…) to change my rendering right ?
Now it’s not blurred anymore but it’s “too sharp” I mean it’s like there’s no antialiasing, even if I change the “samples” settings in my game.project it doesn’t change anything
I think it’s something that happens if you zoom on something that uses nearest as filtering… How did it look with linear? Does it look better if you have nearest and zoom at exactly x2 (0.5 in my example)?