UiAnimate
not sure about the name might change it
What is it?
UiAnimate is a module that allows you to make ui animations with ease.
It allows you to do things like this:
https://i.gyazo.com/f4e5dc758f7193434d94a6285c277f25.mp4
or:
https://i.gyazo.com/a9593190f9486c1f0f4eb02f52fefe53.mp4
With this amount of code:
local UiAnimate = require(game.ReplicatedStorage.UiAnimate)
local TextButton, TextButtonObject = UiAnimate.new(script.Parent)
TextButtonObject:Configuire("Hover", "Grow", {0.01})
And you can also do them at the same time:
https://i.gyazo.com/03733cded96ce15e068f456e30ebd016.mp4
How to use it
First you will need the module:
Source code:
Example code:
local UiAnimate = require(game.ReplicatedStorage.UiAnimate)
local TextButton, TextButtonObject = UiAnimate.new(script.Parent)
TextButtonObject:Configuire("Hover", "Grow", {0.01})
With just 3 lines of code the TextButton will ‘Grow’ by 0.01 when you ‘Hover’ your mouse over it:
https://i.gyazo.com/f4e5dc758f7193434d94a6285c277f25.mp4
Something else you can do is this:
local UiAnimate = require(game.ReplicatedStorage.UiAnimate)
local TextButton, TextButtonObject = UiAnimate.new(script.Parent)
TextButtonObject:Configuire("Hover", "Grow", {0.01})
TextButtonObject:Configuire("Click", "BackgroundColor", {Color3.fromRGB(0, 0, 127), "Left"})
Now when you left click the TextButton its background color will turn to Color3.fromRGB(0, 0, 127):
https://i.gyazo.com/003609281da022f1d83f2a443122fe94.mp4
How it works:
Lets go into the module
We’ll first look at the :Configuire()
function
function AnimateObject:Configuire(Action, Style, ChangeTable)
local Object = self.Object
local ChosenTween = AnimateStyles[Action][Style]
ChosenTween(Object, ChangeTable)
end
It takes 3 parameters.
If we scroll up you will see a table called “AnimateStyles”
This is the way I have it setup:
local AnimateStyles = {
Hover = {};
Click = {};
}
The first table inside of the “AnimateStyles” table are the actions.
So ‘Hover’ is when you hover your mouse over the UiObject.
If you go deeper you will find this:
local AnimateStyles = {
Hover = {
["FunctionName"] = function(Object, ChangeTable)
Object.MouseEnter:Connect(function()
end)
Object.MouseLeave:Connect(function()
end)
end
};
Click = {
};
}
For example this is what the “Grow” function looks like:
Hover = {
["Grow"] = function(Object, ChangeTable)
local OriginalSize = Object.Size
local Amount = ChangeTable[1] or 0.01
Object.MouseEnter:Connect(function()
Object:TweenSize(
UDim2.new(Object.Size.X.Scale + Amount, 0, Object.Size.Y.Scale + Amount, 0),
"In",
"Quad",
0.1,
true
)
end)
Object.MouseLeave:Connect(function()
Object:TweenSize(OriginalSize, "In", "Quad", 0.1, true)
end)
end;
}
Custom Animations:
My favorite thing is that you can add custom animations, this is how:
Say I wanted to make a animation (or function idk what to call them) that when you hover you mouse over the object it will rotate a bit.
local AnimateStyles = {
Hover = {
["Rotate"] = function(Object, ChangeTable)
--I will start by making a few variables:
local OriginalRotation = Object.Rotation
local RotationAmount= ChangeTable[1]
Object.MouseEnter:Connect(function()
TweenService:Create(Object,
TweenInfo.new(0.1,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0),
{Rotation = RotationAmount}
):Play()
end)
Object.MouseLeave:Connect(function()
TweenService:Create(Object,
TweenInfo.new(0.1,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0),
{Rotation = OriginalRotation}
):Play()
end)
end;
};
Now in the you can do this:
TextButtonObject:Configuire("Hover", "Rotate", {11.25})
And it will look like this:
https://i.gyazo.com/85e3a9103baa2dc5ef845d8413cc099b.mp4
Documentation
Function:
.new(Object)
Description
The object is Ui object, it returns the Ui object and the self object.
The reason why I did this is so that you can define the new object while you are defining the variable for the ui element:
local TextButton, TextButtonObject = UiAnimate.new(script.Parent)
Function:
:Configuire(Action, Style, ChangeTable)
Description
Action:
The event that will cause the function to run, eg. Hover will cause the function to run when you hover your mouse over the object.
Style:
The function name, eg. Grow
Change:
This will change depending on what Style you choose, so if you choose “Grow” the change will be the number which you want the Ui object to grow by, but if you are using “TextColor” the change will be a color3 value.
Conclusion
I hope I explained it well enough, If you have any questions ask me please.
If there are any bugs or problems, please please please tell me.
Updates:
Version 1.1:
Changed the way the parameters are setup, they now take a table.
Before:
TextButtonObject:Configuire("Hover", "Shrink", 0.01)
After:
TextButtonObject:Configuire("Hover", "Shrink", {0.01})
This change allows you to do more powerful things.
The ‘RightClick’ and ‘LeftClick’ styles are replaced with ‘Click’ this is because you would have the same functions for 2 different styles.
How to use ‘Click’:
TextButtonObject:Configuire("Click", "Shrink", {0.01, "Left"})--Left click
TextButtonObject:Configuire("Click", "Shrink", {0.01, "Right"})--Right click