Fusion icon indicating copy to clipboard operation
Fusion copied to clipboard

Create Delay objects

Open astrealRBLX opened this issue 3 years ago • 4 comments

Implementation of #74. Value objects can be wrapped in a Delay object to have their state changes delayed. The problem proposed by the original issue can now be easily resolved.

DelayDemo

Example usage:

local springGoal = Value(0)
local delayedSpringGoal = Delay(springGoal, 2) -- Delay state changes by 2 seconds
local spring = Spring(delayedSpringGoal, 5, 1)
New 'TextLabel' {
    Size = Computed(function()
        return UDim2.new(spring:get(), 0, 0.1, 0)
    end)
}
springGoal:set(1)

astrealRBLX avatar Dec 10 '21 04:12 astrealRBLX

This looks absolutely fantastic at first glance - thanks for this contribution!

I'll do a code review when I next have some time available :)

dphfox avatar Dec 10 '21 07:12 dphfox

Seems like a nasty edge case exists here: consider Delay(FollowerState, DurationState)

I don't think this is an edge case. This was mentioned in #74 as a possible problem but I actually specifically implemented it like this because logically it makes sense. The order that state is updated doesn't affect delay objects; the scheduler only cares about making sure they update after their duration has passed. It might also be possible to implement a way to toggle this behavior with an additional parameter to Delay() but I don't want to clutter the constructor too much.

astrealRBLX avatar Dec 10 '21 15:12 astrealRBLX

After some thought, I definitely don't think this way of the Duration parameter as a state is the right direction. It is confusing and not all that useful. If a State is allowed for the duration at all, the behaviour should be that it delays to whatever the follower state was at [duration] time ago.

Dionysusnu avatar Dec 10 '21 16:12 Dionysusnu

I'm considering rolling this into Fusion as part of 0.3's broader animation system overhauls. As such, I'm going to mark this PR as blocked for the time being as we work through the backlog of pull requests.

I plan to merge this in soon. :)

dphfox avatar Feb 01 '23 00:02 dphfox

Closing this PR - but I plan to implement this alongside the rest of the animation changes, which will happen in a different branch. Thanks for the contributions; I'll make sure to refer back to this PR.

dphfox avatar Apr 15 '24 12:04 dphfox