Multi-Image Spritesheet Module

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:

  1. The module is poorly optimized. The module is open source, so feel free to optimize to your heart’s content.
  2. The module uses a slightly hacky method. I’ve found ImageRectOffset and switching the Image properties to be unreliable in the past, so instead I use scaled up images and change their position inside of a ClipsDescendants = true frame, and I change the Visible 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.

1 Like

HI,
Looks cool, do you have a .rbxl with an open source spritesheet to check it out?

Thanks

Sorry for the late reply! Unfortunately I don’t have an open sourced sprite that uses multiple images (I want to keep the one I have private for now) but here is a demo place you can use to play with the module that uses an open source 1 image sprite (you can test your multi image sprites with it:)
SpritesheetDemo.rbxl (52.2 KB)

1 Like