in trying to make it so that whn the player clicks and drags on screen there is a box that follows the mouse, similar to draging in the windows main menu. but the box is not showing up on screen. can anyone help me? this is the script for the boxx object
function init(self)
msg.post(".", "acquire_input_focus")
end
-- Initial click position
local is_dragging = false -- Flag to track if dragging is in progress
local last_action
function on_input(self, action_id, action)
if action_id == hash("drag") then
if action.pressed then
initial_click_position_x = action.x
initial_click_position_y = action.y
-- Mouse button pressed
is_dragging = true
last_action = action
print("Mouse button pressed")
go.set("#box", "tint", vmath.vector4(1, 1, 1, 1)) -- Set color to indicate visibility
elseif action.released then
-- Mouse button released
is_dragging = false
print("Mouse button released")
go.set("#box", "tint", vmath.vector4(1, 1, 1, 0)) -- Set color to indicate invisibility
end
end
end
function update(self, dt)
if is_dragging and last_action then
local current_position = vmath.vector3(last_action.x, last_action.y, 1)
local size = vmath.vector3(math.abs(current_position.x - initial_click_position_x), math.abs(current_position.y - initial_click_position_y), 1)
local position = vmath.vector3((current_position.x + initial_click_position_x) / 2, (current_position.y + initial_click_position_y) / 2, 1)
-- Set the position and size of the box
size.x = math.max(size.x, 0.001)
size.y = math.max(size.y, 0.001)
-- Set the position of the box
go.set_position(position)
go.set_scale(size)
print("Box position set")
end
end