Skip to content

Commit

Permalink
Merge pull request #66 from defold/camera-update
Browse files Browse the repository at this point in the history
Update to use new camera api
  • Loading branch information
Jhonnyg authored Dec 10, 2024
2 parents 05a9c04 + 036c2f8 commit 18518e6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
19 changes: 6 additions & 13 deletions examples/render/camera/camera.script
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
function init(self)
msg.post("#camera", "acquire_camera_focus") -- <1>
msg.post("@render:", "use_camera_projection") -- <2>
end

function on_message(self, message_id, message, sender)
if message_id == hash("follow") then -- <3>
go.set_parent(".", sender) -- <4>
elseif message_id == hash("unfollow") then -- <5>
if message_id == hash("follow") then -- <1>
go.set_parent(".", sender) -- <2>
elseif message_id == hash("unfollow") then -- <3>
go.set_parent("camera", nil, true)
end
end

--[[
1. Acquire camera focus for the camera component. When a camera has focus it will send view and projection updates to the render script.
2. Tell the render script to use the view and projection provided by the camera.
3. Start following the game object that sent the `follow` message.
4. This is done by parenting the camera component to the game object that sent the message.
5. Stop following any game object. This is done removing the parent game object while maintaining the current world transform.
1. Start following the game object that sent the `follow` message.
2. This is done by parenting the camera component to the game object that sent the message.
3. Stop following any game object. This is done removing the parent game object while maintaining the current world transform.
--]]
2 changes: 0 additions & 2 deletions examples/render/orbit_camera/orbit_camera.script
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ go.property("rotation_speed", 0.5)
go.property("offset", vmath.vector3(0, 0, 0))

function init(self)
-- Set the camera projection to be used
msg.post("@render:", "use_camera_projection")
-- Acquire input focus to receive input events
msg.post(".", "acquire_input_focus")

Expand Down
11 changes: 3 additions & 8 deletions examples/render/screen_to_world/bee.script
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ local DISPLAY_HEIGHT = sys.get_config_int("display.height")
-- world coordinates given a camera component
-- this function will use the camera view and projection to
-- translate the screen coordinates into world coordinates
local function screen_to_world(x, y, z, camera)
local projection = go.get(camera, "projection")
local view = go.get(camera, "view")
local function screen_to_world(x, y, z, camera_id)
local projection = camera.get_projection(camera_id)
local view = camera.get_view(camera_id)
local w, h = window.get_size()
-- The window.get_size() function will return the scaled window size,
-- ie taking into account display scaling (Retina screens on macOS for
Expand All @@ -27,11 +27,6 @@ local function screen_to_world(x, y, z, camera)
end

function init(self)
-- activate the camera
msg.post("#camera", "acquire_camera_focus")
-- make sure the render script uses both the view and
-- the camera projection when rendering the world
msg.post("@render:", "use_camera_projection")
-- send input events to this script
msg.post(".", "acquire_input_focus")
end
Expand Down
2 changes: 1 addition & 1 deletion game.project
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title = Defold-examples
version = 0.1
custom_resources = examples/resource/modify_atlas/resources
dependencies#0 = https://github.com/defold/extension-spine/archive/refs/tags/3.5.3.zip
dependencies#0 = https://github.com/defold/extension-spine/archive/refs/tags/3.6.2.zip

[bootstrap]
main_collection = /examples/main.collectionc
Expand Down

0 comments on commit 18518e6

Please sign in to comment.