Hello. I created custom matrix for my ui.
render.set_view(vmath.matrix4())
render.set_projection(vmath.matrix4_orthographic(0, ui_projection_width, 0, ui_projection_height, -1, 1))
render.set_viewport(ui_viewport_x, ui_viewport_y, ui_viewport_width, ui_viewport_height)
and then i use following function to convert screen coordinates to UI coordinates
function update_screen_position(screen_position_x, screen_position_y)
screen_ui_position.x = (screen_position_x - ui_viewport_x) / ui_screen_ratio.x
screen_ui_position.y = (screen_position_y - ui_viewport_y) / ui_screen_ratio.y
end
I have base UI size 800/600 and somewhere in render script i calculate ui_screen_ratio. so my function works well on desktop when i call it and handle in gui script like in code below
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
pprint(action)
update_screen_position(action.screen_x, action.screen_y)
if gui.pick_node(self.ui.buttons.restart, screen_ui_position.x, screen_ui_position.y) then
msg.post("default:/board#controller", RESTART_MESSAGE, {})
elseif gui.pick_node(self.ui.buttons.help, screen_ui_position.x, screen_ui_position.y) then
change_state(self, STATE_HELP)
elseif gui.pick_node(self.ui.buttons.twitter, screen_ui_position.x, screen_ui_position.y) then
open_twitter(self)
elseif gui.pick_node(self.ui.buttons.help_back, screen_ui_position.x, screen_ui_position.y) then
change_state(self, STATE_BASE)
end
end
end
problem happens when i come to android. action.x and action.y contains another coordinates not the same as screen pixel positions. and even if i use action.screen_x and action.screen_y sims like gui.pick_node doesn’t handle rects with calculated screen coordinates