46 lines
1.4 KiB
Text
46 lines
1.4 KiB
Text
function init(self)
|
|
|
|
end
|
|
|
|
function final(self)
|
|
-- Add finalization code here
|
|
-- Learn more: https://defold.com/manuals/script/
|
|
-- Remove this function if not needed
|
|
end
|
|
|
|
function update(self, dt)
|
|
--gui.set_position(gui.get_node("sound_bar"), pos)
|
|
end
|
|
|
|
function on_message(self, message_id, message, sender)
|
|
if message_id == hash("new_volume") then
|
|
self.volume = message.new_volume
|
|
local volume_pos = gui.get_position(gui.get_node("sound_bar"))
|
|
gui.set_position(gui.get_node("sound_bar"), vmath.vector3(self.volume, volume_pos.y, volume_pos.z))
|
|
end
|
|
end
|
|
|
|
function on_input(self, action_id, action)
|
|
if action_id == hash("touch") and action.pressed then
|
|
if gui.pick_node(gui.get_node("sound_bar"), action.x, action.y) then
|
|
self.dragging = true
|
|
end
|
|
elseif action.released then
|
|
self.dragging = false
|
|
end
|
|
if self.dragging then
|
|
local volume_pos = gui.get_position(gui.get_node("sound_bar"))
|
|
if action.x >= 547 and action.x <= 887 then
|
|
gui.set_position(gui.get_node("sound_bar"), vmath.vector3(action.x, volume_pos.y, volume_pos.z))
|
|
msg.post("main:/controller#main", "new_volume", { new_volume = action.x })
|
|
end
|
|
-- print(volume)
|
|
-- msg.post("main:/controller#main", "set_volume", { volume = volume })
|
|
end
|
|
end
|
|
|
|
function on_reload(self)
|
|
-- Add reload-handling code here
|
|
-- Learn more: https://defold.com/manuals/hot-reload/
|
|
-- Remove this function if not needed
|
|
end
|