thanks to Eisher, my rotate is working, but funny enough, only with wheel up or down, not with right-click. I use Defold 2, and I add the mouse event. Maybe my code is faulty ?
this set up is working with
function init(self)
msg.post(".", “acquire_input_focus”)
self.collision_id = nil
end
function final(self)
msg.post(".", "release_input_focus")
end
function update(self)
--self.collision_id = nil
end
function on_message(self, message_id, message, sender)
if message_id == hash(“collision_response”) then
if not self.collision_id or go.get_position(self.collision_id).z < message.other_position.z then
self.collision_id = message.other_id
end
end
end
function on_input(self, action_id, action)
– update cursor position
go.set_position(vmath.vector3(action.x, action.y, 0))
if self.collision_id and action.pressed then
self.dragged_ts = socket.gettime()
self.dragged_id = self.collision_id
elseif action.released then
self.dragged_id = nil
end
– we’re dragging if we have a dragged_id and the time since action.pressed is larger than 0.5 seconds
local is_dragging = self.dragged_id and (socket.gettime() - self.dragged_ts >= 0.5) or false
– if we’re colliding with something and the user clicked we track the id and the time when it happened
if self.collision_id and action.pressed then
self.dragged_ts = socket.gettime()
self.dragged_id = self.collision_id
elseif action.released then
self.dragged_id = nil
end
if not action_id or action_id == hash("touch") and is_dragging then
local url = msg.url(nil, "picot", "sprite")
local widthpicot = go.get(url, "size.x")
local heightpicot = go.get(url, “size.y”)
--go.set_position(vmath.vector3(math.round((action.x)/16)*16+math.round(widthpicot/2), math.round((action.y)/16)*16+1+math.round(heightpicot/2), 0), self.dragged_id)
go.set_position(vmath.vector3(math.floor((action.x)/16)*16+math.floor(widthpicot/2), math.floor((action.y)/16)*16+math.floor(heightpicot/2)+1, 0), self.dragged_id)
end
if action_id == hash("rotate") then
local current_rot = go.get_rotation()
local rot = vmath.quat_rotation_z(math.pi / 2)
go.set_rotation(current_rot * rot,self.dragged_id)
end
end
function on_reload(self)
– Add reload-handling code here
– Remove this function if not needed
end
If I set up mouse trigger on right-click instead of wheel up, there is no rotation happening