AGulev
July 17, 2019, 12:49pm
14
Yes, it’s not a bug on Defold side. You just need to to use screen coordinates (screen_x
, screen_y
) and convert them to you adjust mode using this module, for example:
This is implementation of gui.set_screen_position() and gui.screen_pos_to_node_pos() functions for Defold. This library will be useful if you want to get screen position of the node and set this position for another node with the different parent of even in another component.
Installation
You can use this library in your own project by adding this project as a Defold library dependency . Open your game.project file and in the dependencies field under project add:
https://github.com/AGulev/se…
Or check @britzl 's example virtual gamepad here:
local function post_to_listener(self, message_id, message)
if self.listener then
msg.post(self.listener, message_id, message or {})
end
end
local function on_analog(self, touch, control)
local touch_position = vmath.vector3(touch.x, touch.y, 0)
if touch.pressed then
gui.cancel_animation(control.node, gui.PROP_POSITION)
control.analog_pos = touch_position
control.analog_offset = touch_position - control.node_start_position
elseif touch.released then
gui.animate(control.node, gui.PROP_POSITION, control.node_start_position, gui.EASING_OUTQUAD, 0.2)
post_to_listener(self, "analog", { x = 0, y = 0 })
else
local diff = control.analog_pos - touch_position
local dir = vmath.normalize(diff)
local distance = vmath.length(diff)
if distance > 0 then
This file has been truncated. show original
2 Likes