Module components_draggable
Makes a game object follow the touch while its box collider is pressed.
Info:
- Author: Sharper Dev
Functions
| Draggable:new (gameObject) | Creates a draggable component; requires an existing BoxCollider. |
| Draggable:registerFunctions () | Assigns touch-down and touch-up handlers to the required BoxCollider. |
| Draggable:update () | While dragging, moves the game object to the current touch position and calls onDragging. |
| Draggable:onDragStart () | Override to handle the start of a drag, triggered by collider touch-down. |
| Draggable:onDragging () | Override to handle each update while dragging; called after moving the object. |
| Draggable:onDragEnd () | Override to handle the end of a drag, triggered by collider touch-up. |
Local Functions
| onTouchDown (self) | Begins dragging and invokes the drag-start callback. |
| onTouchUp (self) | Ends dragging and invokes the drag-end callback. |
Functions
- Draggable:new (gameObject)
-
Creates a draggable component; requires an existing BoxCollider.
Parameters:
- gameObject table Game object to move while dragging.
Returns:
-
table The new Draggable component.
Usage:
local draggable = gameObject:addComponent("Draggable")
- Draggable:registerFunctions ()
- Assigns touch-down and touch-up handlers to the required BoxCollider.
- Draggable:update ()
- While dragging, moves the game object to the current touch position and calls onDragging.
- Draggable:onDragStart ()
-
Override to handle the start of a drag, triggered by collider touch-down.
Usage:
function draggable:onDragStart() -- Code here end
- Draggable:onDragging ()
-
Override to handle each update while dragging; called after moving the object.
Usage:
function draggable:onDragging() -- Code here end
- Draggable:onDragEnd ()
-
Override to handle the end of a drag, triggered by collider touch-up.
Usage:
function draggable:onDragEnd() -- Code here end