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
Tween
DescriptionTween class which linearly interpolates a quantity from a start value to an end value over a given duration.Functions
applyValue
DescriptionApply a value via the setter function.Definition
applyValue()Code
96 | function Tween:applyValue(newValue) |
97 | if self.functionTarget ~= nil then |
98 | self.setter(self.functionTarget, newValue) |
99 | else |
100 | self.setter(newValue) |
101 | end |
102 | end |
getDuration
DescriptionGet this tween's duration in milliseconds.Definition
getDuration()Code
43 | function Tween:getDuration() |
44 | return self.duration |
45 | end |
getFinished
DescriptionCheck if this tween has finished.Definition
getFinished()Code
49 | function Tween:getFinished() |
50 | return self.isFinished |
51 | end |
new
DescriptionCreate a new Tween.Definition
new(table subClass, function setterFunction, float startValue, float endValue, float duration)Arguments
table | subClass | Subclass metatable for inheritance |
function | setterFunction | Value setter function. Signature: callback(value) or callback(target, value). |
float | startValue | Original value |
float | endValue | Target value |
float | duration | Duration of tween in milliseconds |
20 | function Tween.new(subClass, setterFunction, startValue, endValue, duration) |
21 | if not subClass or subClass == Tween then |
22 | subClass = Tween_mt |
23 | end |
24 | |
25 | local self = setmetatable({}, subClass) |
26 | |
27 | self.setter = setterFunction |
28 | self.startValue = startValue |
29 | self.endValue = endValue |
30 | self.duration = duration |
31 | self.elapsedTime = 0 |
32 | |
33 | self.isFinished = duration == 0 |
34 | self.functionTarget = nil |
35 | |
36 | self.curveFunc = Tween.CURVE.LINEAR |
37 | |
38 | return self |
39 | end |
reset
DescriptionReset this tween to play it again.Definition
reset()Code
55 | function Tween:reset() |
56 | self.elapsedTime = 0 |
57 | self.isFinished = self.duration == 0 |
58 | end |
setCurve
DescriptionSet the curve function. Defaults to Tween.CURVE.LINEARDefinition
setCurve()Code
106 | function Tween:setCurve(func) |
107 | self.curveFunc = func or Tween.CURVE.LINEAR |
108 | 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
63 | function Tween:setTarget(target) |
64 | self.functionTarget = target |
65 | end |
tweenValue
DescriptionGet the current tween value.Definition
tweenValue()Code
90 | function Tween:tweenValue(t) |
91 | return MathUtil.lerp(self.startValue, self.endValue, self.curveFunc(t)) |
92 | end |
update
DescriptionUpdate the tween's state.Definition
update()Code
69 | function Tween:update(dt) |
70 | if self.isFinished then |
71 | return |
72 | end |
73 | |
74 | self.elapsedTime = self.elapsedTime + dt |
75 | |
76 | local newValue |
77 | if self.elapsedTime >= self.duration then |
78 | self.isFinished = true |
79 | newValue = self:tweenValue(1) |
80 | else |
81 | local t = self.elapsedTime / self.duration |
82 | newValue = self:tweenValue(t) |
83 | end |
84 | |
85 | self:applyValue(newValue) |
86 | end |