This is by no means new and perhaps somebody has made a public method before, but I decided to make my own today. It was originally just for a friend to use, but I might as well make it public.
With that out of the way, let me introduce my new Gif Element:
Gif v1 (Old)
Here’s the description as I’ve put it:
A “new” UI element used to for “gifs” instead of plain images.
No need to touch any code as all you’ll need is accessible via the ‘attributes’ section of its properties.
Instructions
1. Convert your gif (or video) into a sprite sheet with 0 spacing between sprites.
2. Upload your sprite sheet as a decal.
3. Copy the asset ID (different from the decal ID) and paste it into the ‘Image’ attribute.
4. Fill out the rest of the attributes with the required sprite sheet information.
The required attributes are the following:
Frames: Number of individual sprites on the sprite sheet.
Grid: The size of the sprite sheet grid (X,Y). (Number of sprites)
Size: The pixel size of the original gif (X,Y).
How to Use
- AspectRatio: Toggles correct aspect ratio.
- Playing: Toggles if the gif is playing (pause/resume).
-
Play: Triggers
Play()
function. (Begins playing gif from start) -
Stop: Triggers
Stop()
function. (Stops playing gif and returns to start) - Speed: Controls the speed at which the gif plays. (Decimal: Minimum 0, maximum 1)
- Looped: Toggles whether or not the gif will repeat after completion.
I’ve personally been using EzGif, but any tool will work as long as the sprite spacing is 0.
This is my first user friendly asset I’ve created in a long time. Let me know if anything is confusing or could otherwise be simplified or improved in some way.
Gif.rbxm (5.4 KB)
^ Forgot to add the download.
Also available as a model here.
Notice:
There are some known bugs that I’ve discovered while trying to iterate between multiple gifs in a sort of looping “playlist” format. When I have the time to spare, I will be rewriting this to be more script friendly.
Gif v2:
Changes:
- Removed all “function” controls from the attributes.
- Added Bindable functions/events instead.
- Removed “AspectRatio” and “Size” attributes as they were redundant.
- Replaced “Speed” attribute with “FPS” attribute.
- Officially and properly script compatible (mostly tested).
Instructions
1. Convert your gif (or video) into a sprite sheet with 0 spacing between sprites.
2. Upload your sprite sheet as a decal.
3. Copy the asset ID (different from the decal ID) and paste it into the ‘Image’ attribute.
4. Fill out the rest of the attributes with the required sprite sheet information.
How to Use
Attributes:
FPS:
Controls the frames per second (speed).
Frames:
Sets the number of frames that the gif has.
Grid:
Sets the grid (X,Z) of the gif’s frames.
Image:
Sets the ImageId of the gif’s image.
Looped:
Controls if the gif will loop or not.
Playing:
Shows whether or not the gif is playing.
Also acts as a resume/pause toggle.
Functions:
Play: Gif.Play.Invoke()
Plays the gif from the beginning.
Stop: Gif.Stop.Invoke()
Stops the gif and resets it to the first frame.
Pause: Gif.Pause.Invoke()
Pauses the gif at its current frame.
Resume: Gif.Resume.Invoke()
Resumes the gif at its current frame.
Events:
AttributeChanged: Gif.Attributechanged.Event:Connect()
Fires when an attribute of the gif has changed.
Returns the name of the attribute changed.
DidLoop: Gif.DidLoop.Event:Connect()
Fires when the gif loops.
Ended: Gif.Ended.Event:Connect()
Fires when the gif has ended.
Loaded: Gif.Loaded.Event:Connect()
Fires when the gif image has loaded successfully.
Paused: Gif.Paused.Event:Connect()
Fires when the gif has paused.
Played: Gif.Played.Event:Connect()
Fires when the gif has been played (using the “Play” function).
Resumed: Gif.Resumed.Event:Connect()
Fires when the gif has been resumed (unpaused).
Stopped: Gif.Stopped.Event:Connect()
Fires when the gif has been stopped (using the “Stop” function).
Example:
I’ve personally been using EzGif, but any tool will work as long as the sprite spacing is 0.
Download:
Gif.rbxm (8.5 KB)
Model:
Please let me know if you find any bugs or issues. I’m also open to any suggestions.