I am trying to use the Rendercam to allow the cursor to maintain its same position relative to the screen when zooming in and out using the camera however now I have done this the cursor game object no longer matches the position of the cursor on screen, and instead maintains a position in the bottom left corner of the screen. While I am glad that the game objects position is now relative to the screen now it doesn’t follow the cursor.
This is the code the game object which controls the zooming in and out and updating the position of the cursor:
local rendercam = require "rendercam.rendercam"
local mouse_spos = vmath.vector3()
local mouse_wpos = vmath.vector3()
local zstep = 10
local cursor = msg.url("main", "/cursor", "cursor")
function init(self)
msg.post(".", "acquire_input_focus")
self.mouse_spos = vmath.vector3()
end
function update(self, dt)
self.mouse_wpos = rendercam.screen_to_world_2d(self.mouse_spos.x, self.mouse_spos.y)
msg.post(cursor, "update pos", {pos = self.mouse_wpos})
end
function on_input(self, action_id, action)
if action_id == hash("zoomin") then
rendercam.zoom(-zstep)
elseif action_id == hash("zoomout") then
rendercam.zoom(zstep)
end
end
function final(self)
msg.post(".", "release_input_focus")
end
And this is the code for the cursor:
function init(self)
self.pos = go.get_position()
end
function on_message(self, message_id, message, sender)
if message_id == hash("update pos") then
self.pos = message.pos
go.set_position(self.pos)
end
end
This is a video showing what is happening. The white orb is supposed to be at the position of the mouse cursor. The Defold logo is just for scale