For the past week or so now I’ve wanted to add a sprite to my game, while still preserving the image quality (due to roblox downscaling large images.) The solution I came up with was a system that accepted a table of images. After a couple of failed attempts, this module is the result!
Some things to note:
- The module is poorly optimized. The module is open source, so feel free to optimize to your heart’s content.
-
The module uses a slightly hacky method. I’ve found
ImageRectOffset
and switching theImage
properties to be unreliable in the past, so instead I use scaled up images and change their position inside of aClipsDescendants = true
frame, and I change theVisible
property to switch between images.
Other than that, its usage is pretty simple. The only method is .new()
. There is only one parameter, and that is a table (full of parameters lol.) Here’s an example of some code to help with assembly:
local module = require() -- path to module
local info = {
Images = {"rbxassetid://15038884804"}, -- these are in index order, make sure the ID is of the image and NOT the decal, and it MUST have this format. Although there's only one image here, I've tested it and it works with multiple.
Size = Vector2.new(400,400), -- X and Y size (in offset) that YOU want to have (not actual dimensions of the image)
imgtransparency = 0.5, -- self explanatory
resample = Enum.ResamplerMode.Default, -- render appearance, you can set to Pixelate instead of Default
X = 8, -- number of horizontal frames
Frames = 64, -- number of frames in each spritesheet; this assumes all sheets have the same number
fps = 30, -- self explanatory
cycles = -1 -- how many times the animation will play; set it to -1 for infinite
}
local sprite = module.new(info)
-- to change things like the parent and position of the sprite, call sprite.bg to get the container that holds all of the image labels
sprite.bg.Parent = gui
Let me know if you have any feedback (on the module or on how I should properly post on the forum) and you can get the module here.