rbx-dragger v1.0.0
rbx-dragger provides an easy-to-use solution for implementing draggable GUI elements in your Roblox games.
Features
- Simple API for creating draggable objects
- Customizable drag behavior
- Rate limiting for performance optimization
- Separate target object support
- Event signals for drag start, drag, and drag end
- Optional key binding for drag activation
- Multiple drag types, such as rotate, linear translate and plane translate
Quick Example
local dragger = require(path.to.rbx_dragger)
local success, myDragger = dragger.new({
object = myDraggableFrame,
rate_limit = 2, -- Update every 2 input changes
update = true -- Automatically update position (default)
})
if success then
myDragger:enable()
myDragger.drag_started:Connect(function()
print("Started dragging!")
end)
myDragger.dragged:Connect(function(newPosition)
print("New position:", newPosition)
end)
myDragger.drag_ended:Connect(function()
print("Finished dragging!")
end)
end
Key Features Explained
- Easy Setup: Create a dragger with a single function call.
- Rate Limiting: Optimize performance by controlling how often the drag updates.
- Separate Target: Optionally drag a different object than the one receiving input.
- Auto-updating: Choose whether the module automatically updates the object’s position or let you handle it manually.
- Event Signals: Connect to drag events for custom behaviors.
- Key Binding: Optionally require a key to be held for dragging (great for building tools!).
- Drag Modes: Choose the response behaviour to a drag input
Installation
- Insert the .rbxm file from the Github Releases page into your Studio game or add the marketplace asset to your toolbox.
- Place the module in your game (e.g., in ReplicatedStorage).
- Require the module in your scripts.
API Overview
dragger.new(info: dragger_info) -> (boolean, dragger?)
type drag_mode = "rotate" | "plane" | "linear"
type dragger_info =
{
object : GuiObject,
target : GuiObject?, -- default object
rate_limit : number?, -- default 1
update : boolean?, -- default true
drag_mode : drag_mode?, -- default "plane"
drag_axis : Vector2?, -- default Vector2.new(1, 0)
}
type dragger = {
-- Properties
object: prop<GuiObject>,
target: prop<GuiObject>,
rate_limit: prop<number>,
update: prop<boolean?>,
dragging: immutable_prop<boolean>,
drag_count: immutable_prop<number>,
enabled: immutable_prop<boolean>,
drag_mode : prop<drag_mode>,
drag_axis : prop<Vector2>,
-- Events
drag_started: restricted_signal,
dragged: restricted_signal,
drag_ended: restricted_signal,
-- Methods
enable: (self: any, key_code: Enum.KeyCode?) -> (),
disable: (self: any) -> ()
}
Feedback and Contributions
I’d love to hear your thoughts on this module! Feel free to leave comments, suggestions, or report any issues you encounter. If you’d like to contribute to the project, check out the GitHub repository and submit a pull request.
Happy dragging!