rbx-dragger
I’ve been working on called rbx-dragger. This module 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
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!).
Installation
- Get the module from the rbx-dragger GitHub repository. Or add the roblox 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 dragger_info = {
object: GuiObject,
target: GuiObject?,
rate_limit: number?,
update: boolean?,
}
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>,
-- 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!