Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ContextActionDisplay
- DialogElement
- FieldInfoDisplay
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputHelpDisplay
- ListElement
- ListItemElement
- MapHotspot
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- SettingsModel
- SideNotification
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- StableListElement
- StatusBar
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TextElement
- TextInputElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
TweenSequence
DescriptionAllows setting up more complex tweening by defining sequences of tweens, intervals and callbacks. A sequence is itself a Tween, so you may even define and add sub-sequences. Before a sequence reacts to update() calls, it must be started with start(). This also applies after resetting. Adding tweens, callbacks and intervals will append them to the current sequence. Insertion of tweens and callbacks will insert them at the given relative instants, allowing for overlapping tweens and arbitrary callback times. Inserting an interval will push pack all later instants by the given time.Parent
TweenFunctions
- addCallback
- addInterval
- addTween
- getDuration
- insertCallback
- insertInterval
- insertTween
- new
- reset
- setLooping
- setTarget
- start
- stop
- update
- updateCallbacks
- updateTweens
addCallback
DescriptionAdd a callback at the end of the sequence.Definition
addCallback(function callback, table callbackState)Arguments
function | callback | Callback function with signature of either callback(target, value) or callback(value) |
table | callbackState | Any value which is passed to the callback as its first (no target) or second (with target) argument |
107 | function TweenSequence:addCallback(callback, callbackState) |
108 | self:insertCallback(callback, callbackState, self.totalDuration) |
109 | end |
addInterval
DescriptionAdd an interval at the end of the sequence. Use this to add a pause to the sequence.Definition
addInterval()Code
88 | function TweenSequence:addInterval(interval) |
89 | self:insertInterval(interval, self.totalDuration) |
90 | end |
addTween
DescriptionAdd a tween to the end of the sequence.Definition
addTween(table tween)Arguments
table | tween | Tween instance |
58 | function TweenSequence:addTween(tween) |
59 | self:insertTween(tween, self.totalDuration) |
60 | end |
getDuration
DescriptionGet this tween's duration in milliseconds.Definition
getDuration()Code
113 | function TweenSequence:getDuration() |
114 | return self.totalDuration |
115 | end |
insertCallback
DescriptionInsert a callback at the given instant.Definition
insertCallback(function callback, table callbackState, float instant)Arguments
function | callback | Callback function with signature of either callback(target, value) or callback(value) |
table | callbackState | Any value which is passed to the callback as its first (no target) or second (with target) argument |
float | instant | Time in milliseconds after sequence start |
97 | function TweenSequence:insertCallback(callback, callbackState, instant) |
98 | self.callbackInstants[callback] = instant |
99 | self.callbackStates[callback] = callbackState |
100 | self.callbacksCalled[callback] = false |
101 | end |
insertInterval
DescriptionInsert an interval at the given instant. This will push back all later instants by the interval. Use this to insert pauses into the sequence.Definition
insertInterval(float interval, float instant)Arguments
float | interval | Interval time in milliseconds |
float | instant | Time in milliseconds after sequence start |
67 | function TweenSequence:insertInterval(interval, instant) |
68 | for tween, range in pairs(self.tweenUpdateRanges) do |
69 | local tweenStartInstant, tweenEndInstant = range[1], range[2] |
70 | if tweenStartInstant >= instant then |
71 | self.tweenUpdateRanges[tween][1] = tweenStartInstant + interval |
72 | self.tweenUpdateRanges[tween][2] = tweenEndInstant + interval |
73 | end |
74 | end |
75 | |
76 | for callback, callbackInstant in pairs(self.callbackInstants) do |
77 | if callbackInstant >= instant then |
78 | self.callbackInstants[callback] = callbackInstant + interval |
79 | end |
80 | end |
81 | |
82 | self.totalDuration = self.totalDuration + interval |
83 | end |
insertTween
DescriptionInsert a tween at a given instant.Definition
insertTween(table tween, float instant)Arguments
table | tween | Tween instance |
float | instant | Time in milliseconds after sequence start |
45 | function TweenSequence:insertTween(tween, instant) |
46 | self.tweenUpdateRanges[tween] = {instant, instant + tween:getDuration()} |
47 | |
48 | self.totalDuration = math.max(instant + tween:getDuration(), self.totalDuration) |
49 | |
50 | if self.functionTarget ~= nil then |
51 | tween:setTarget(self.functionTarget) |
52 | end |
53 | end |
new
DescriptionCreate a new TweenSequence.Definition
new(table functionTarget)Arguments
table | functionTarget | [optional] Target table which is supplied by default to all tween setter functions and callbacks as the first argument. If not specified, the setters and callbacks will be called with one value only. |
24 | function TweenSequence.new(functionTarget) |
25 | local self = TweenSequence:superClass().new(TweenSequence_mt) |
26 | |
27 | self.functionTarget = functionTarget |
28 | self.callbackStates = {} -- callback -> callback state |
29 | self.callbacksCalled = {} -- callback -> bool |
30 | |
31 | self.tweenUpdateRanges = {} -- tween -> {startInstant, endInstant} |
32 | self.callbackInstants = {} -- callback -> instant |
33 | |
34 | self.isLooping = false |
35 | self.totalDuration = 0 |
36 | self.isFinished = true |
37 | |
38 | return self |
39 | end |
reset
DescriptionReset the sequence to its initial state.Definition
reset()Code
146 | function TweenSequence:reset() |
147 | self.elapsedTime = 0 |
148 | self.isFinished = true |
149 | |
150 | for tween in pairs(self.tweenUpdateRanges) do |
151 | tween:reset() |
152 | end |
153 | |
154 | for callback in pairs(self.callbacksCalled) do |
155 | self.callbacksCalled[callback] = false |
156 | end |
157 | end |
setLooping
DescriptionSet the looping state for this sequence.Definition
setLooping(bool isLooping)Arguments
bool | isLooping | If true, will restart the sequence when finished, including callbacks! |
127 | function TweenSequence:setLooping(isLooping) |
128 | self.isLooping = isLooping |
129 | end |
setTarget
DescriptionSet a callback target for this tween. If a target has been set, the setter function must support receiving the target as its first argument.Definition
setTarget()Code
120 | function TweenSequence:setTarget(target) |
121 | self.functionTarget = target |
122 | end |
start
DescriptionStart the sequence. A sequence will only update its state when it has been started.Definition
start()Code
134 | function TweenSequence:start() |
135 | self.isFinished = false |
136 | end |
stop
DescriptionStop the sequence.Definition
stop()Code
140 | function TweenSequence:stop() |
141 | self.isFinished = true |
142 | end |
update
DescriptionUpdate the sequence state over time.Definition
update()Code
161 | function TweenSequence:update(dt) |
162 | if not self.isFinished then |
163 | local lastUpdateInstant = self.elapsedTime |
164 | self.elapsedTime = self.elapsedTime + dt |
165 | |
166 | local allFinished = self:updateTweens(lastUpdateInstant, dt) |
167 | self:updateCallbacks() |
168 | |
169 | if self.elapsedTime >= self.totalDuration and allFinished then |
170 | if self.isLooping then |
171 | self:reset() |
172 | self:start() |
173 | else |
174 | self.isFinished = true |
175 | end |
176 | end |
177 | end |
178 | end |
updateCallbacks
DescriptionUpdate callback states.Definition
updateCallbacks()Code
201 | function TweenSequence:updateCallbacks() |
202 | for callback, instant in pairs(self.callbackInstants) do |
203 | if not self.callbacksCalled[callback] and instant <= self.elapsedTime then |
204 | if self.functionTarget ~= nil then |
205 | callback(self.functionTarget, self.callbackStates[callback]) |
206 | else |
207 | callback(self.callbackStates[callback]) |
208 | end |
209 | |
210 | self.callbacksCalled[callback] = true |
211 | end |
212 | end |
213 | end |
updateTweens
DescriptionUpdate active sequence tweens.Definition
updateTweens(float lastInstant, float dt)Arguments
float | lastInstant | Last instant which received an update |
float | dt | Delta time |
184 | function TweenSequence:updateTweens(lastInstant, dt) |
185 | local allFinished = true |
186 | |
187 | for tween, range in pairs(self.tweenUpdateRanges) do |
188 | local tweenStart, tweenEnd = range[1], range[2] |
189 | if not tween:getFinished() and self.elapsedTime >= tweenStart then |
190 | local maxDt = math.min(self.elapsedTime - tweenStart, dt) |
191 | tween:update(maxDt) |
192 | allFinished = allFinished and tween:getFinished() |
193 | end |
194 | end |
195 | |
196 | return allFinished |
197 | end |