Last active
May 3, 2017 12:50
-
-
Save tomires/9f9472d01cda1dd9b2efabe97128b3cc to your computer and use it in GitHub Desktop.
Defold - mouse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function map(var, min, max) | |
if var < min then | |
return min | |
elseif var > max then | |
return max | |
else | |
return var | |
end | |
end | |
function init_cursor(self) | |
self.cursor = gui.get_node("cursor") | |
self.last_cursor_position = vmath.vector3(0, 0, 0) | |
end | |
function cursor_coordinates(self, action) | |
if self.screen == nil then return end | |
local cursor_pos_offset = vmath.vector3(action.x, action.y, 0) - self.last_cursor_position | |
local cursor_pos = gui.get_position(self.cursor) + cursor_pos_offset | |
cursor_pos.x = map(cursor_pos.x, 0, self.screen.x) | |
cursor_pos.y = map(cursor_pos.y, 0, self.screen.y) | |
gui.set_position(self.cursor, cursor_pos) | |
self.last_cursor_position = vmath.vector3(action.x, action.y, 0) | |
return cursor_pos | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment