Terpy v1.3.2
Bug Fixes
- Fixed viewport frames not being supported.
Pretty cool!!!
I will be using this.
Additions
includeDescendantTerpies
when setting and tweening a Terpy’s transparency.Changes (non-breaking)
Bug Fixes
Additions
Terpy:FromInstance()
to retrieve an already made Terpy on an object.Terpy:SetTransparency(0)
.Wow, this is an amazing module. Actually one of those rare modules I could use for my experience out of the box without needing to tweak it’s sources.
Supereasy to use.
Thanks a lot for making and sharing it!
I’m not sure if this is a valid suggestion as I didn’t check all the containers Terpy can run on, but a possible improvement could be to set Visible false/true of the container the Terpy was created for when transparency reaches/leaves 1.
But it was also pretty easy to do that with current implementation. Example:
Time:GetAttributeChangedSignal("Visible"):Connect(function()
-- Wait for existing Tween to complete
if FrameTween and FrameTween.PlaybackState ~= Enum.PlaybackState.Completed then
FrameTween.Completed:Wait()
-- Do a wait() here to allow connected function to run.
task.wait()
end
if Time:GetAttribute("Visible") then
-- Set Frame visible, tween in transparency
Frame.Visible = true
local tweenInfo = TweenInfo.new(0.5)
FrameTween = FrameTerpy:TweenTransparency(tweenInfo, 0)
else
-- Tween out Frame's transparency
local tweenInfo = TweenInfo.new(1)
FrameTween = FrameTerpy:TweenTransparency(tweenInfo, 1)
FrameTween.Completed:Once(function()
-- Set Frame invisible when Tween is completed
Frame.Visible = false
end)
end
end)
Thanks!
As you said, it’s pretty easy to do it. You can simplify your code a little bit though keeping in mind that calling FrameTerpy:TweenTransparency()
cancels the current tween:
Time:GetAttributeChangedSignal("Visible"):Connect(function()
if Time:GetAttribute("Visible") then
-- Set Frame visible, tween in transparency
Frame.Visible = true
FrameTerpy:TweenTransparency(TweenInfo.new(0.5), 0)
else
-- Tween out Frame's transparency
FrameTerpy:TweenTransparency(TweenInfo.new(0.5), 1).Completed:Once(function(playbackState)
if playbackState == Enum.PlaybackState.Completed then
-- Set Frame invisible when Tween is completed
Frame.Visible = false
end
end)
end
end)
This module is exactly what I needed, but I think the module can be further improved.
At the moment, some things are really holding it back for me, like the fact that it returns a Tween
object instead of a Promise. Using a Promise is good practice for dealing with tweening, and can make it composable and cancellable. If cancelled, the tweens should either be cancelled or instantly go to the target transparency (I am not so sure what behavior is preferred). Then, you could do stuff like this:
local terpyPromise = terpy:PromiseTweenTransparency(TweenInfo.new(0.5),0.8)
:andThen(return terpy:PromiseTweenTransparency(TweenInfo.new(1),0.2))
:andThenCall(print, "Tween completed")
:catch(warn)
:finallyCall(print, "Promise settled")
task.wait(0.75)
terpyPromise:cancel()
One of Terpy’s primary use cases is to either hide (transparencies to 1) or show (transparencies to original values) the object. Therefore, I propose adding PromiseShow and PromiseHide methods, each with a doNotTween
argument in case you want to set the transparency instantly. Something along the lines of this:
function Terpy:PromiseShow(doNotTween)
if doNotTween then
self:_setTransparency(...)
return Promise.resolve()
end
return Promise.resolve()
:finallyCall(self:PromiseTweenTranparency, self._showTweenInfo, ...)
:catch(warn)
end
I also suggest adding some setter methods to set the parameters for the PromiseTweenTransparency call inside the PromiseShow and PromiseHide methods. That way, you only have to set your desired parameters once when creating the inital Terpy object, unlike now.
I hope my suggestions are helpful!
I like the suggestion! I have completely done away with the OOP oriented approach to this though, realizing that it can all be encapsulated in a single function:
ChangeTransparency(objs, transparency, tweenInfo, changeTransparencySettings)
There are A LOT of edge cases when it comes to this transparency thing so just having a single function to handle changing transparency on objects when you want to is, I think, the best solution. I have been able to handle many of these cases with my current implementation, but there will always be more I’m sure. I’m not planning on supporting this any further, but I will create a new post containing the source for those that are interested.