Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- 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
- JointConstructor:setActors
- JointConstructor:setJointTransforms
- addDifferential
- addForce
- addImpulse
- addTorque
- addTorqueImpulse
- addVehicleLink
- computeWheelShapeTireForces
- createCCT
- createWheelShape
- getAngularDamping
- getAngularVelocity
- getCCTCollisionFlags
- getCenterOfMass
- getCollisionMask
- getDensity
- getLinearDamping
- getLinearVelocity
- getMass
- getMotorRotationSpeed
- getRigidBodyType
- getVelocityAtLocalPos
- getVelocityAtWorldPos
- getVolume
- getWheelShapeAxleSpeed
- getWheelShapeContactForce
- getWheelShapeContactNormal
- getWheelShapeContactObject
- getWheelShapeContactPoint
- getWheelShapePosition
- getWheelShapeSlip
- moveCCT
- overlapBox
- overlapSphere
- raycastAll
- raycastClosest
- removeCCT
- setAngularDamping
- setAngularVelocity
- setCenterOfMass
- setCollisionMask
- setFrictionVelocity
- setJointDrive
- setLinearDamping
- setLinearVelocity
- setMass
- setRigidBodyType
- setSolverIterationCount
- setWheelShapeForcePoint
- setWheelShapeProps
- setWheelShapeTireFriction
- simulatePhysics
- simulatePhysicsTimeScale
- updateDifferential
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
AnimationElement
DescriptionAnimated image display element. The animation is created by shifting UV texture coordinates per frame across a suitable texture. Used layers: "image" for the display image.Parent
BitmapElementXML Configuration Parameters
GuiElement#animationOffset | int [optional] Initial frame offset of the animation. |
GuiElement#animationFrames | int [optional] Number of frames to animate, defaults to 8. Base this on the display image. |
GuiElement#animationSpeed | int [optional] Time in milliseconds for each frame, defaults to 120ms. |
GuiElement#animationUVOffset | string [optional] Additional UV offset for this animation in the display image space. Format: "[u]px [v]px" |
Functions
copyAttributes
DescriptionDefinitioncopyAttributes()Code
76 | function AnimationElement:copyAttributes(src) |
77 | AnimationElement:superClass().copyAttributes(self, src) |
78 | |
79 | self.animationDefaultUVs = ListUtil.copyTable(src.animationDefaultUVs) |
80 | self.animationOffset = src.animationOffset |
81 | self.animationFrames = src.animationFrames |
82 | self.animationSpeed = src.animationSpeed |
83 | self.animationUVOffset = src.animationUVOffset |
84 | |
85 | self:setImageUVs(nil, unpack(self.animationDefaultUVs)) |
86 | |
87 | self:setAnimationData() |
88 | end |
loadFromXML
DescriptionDefinitionloadFromXML()Code
39 | function AnimationElement:loadFromXML(xmlFile, key) |
40 | AnimationElement:superClass().loadFromXML(self, xmlFile, key) |
41 | |
42 | self.animationOffset = Utils.getNoNil(getXMLInt(xmlFile, key.."#animationOffset"), self.animationOffset) |
43 | self.animationFrames = Utils.getNoNil(getXMLInt(xmlFile, key.."#animationFrames"), self.animationFrames) |
44 | self.animationSpeed = Utils.getNoNil(getXMLInt(xmlFile, key.."#animationSpeed"), self.animationSpeed) |
45 | |
46 | local animationUVOffset = getXMLString(xmlFile, key.."#animationUVOffset") |
47 | if animationUVOffset ~= nil then |
48 | animationUVOffset = GuiUtils.getNormalizedValues(animationUVOffset, self.imageSize) |
49 | self.animationUVOffset = animationUVOffset[1] |
50 | end |
51 | |
52 | local uvs = GuiOverlay.getOverlayUVs(self.overlay, self:getOverlayState()) |
53 | self.animationDefaultUVs = ListUtil.copyTable(uvs) |
54 | |
55 | self:setAnimationData() |
56 | end |
loadProfile
DescriptionDefinitionloadProfile()Code
60 | function AnimationElement:loadProfile(profile, applyProfile) |
61 | AnimationElement:superClass().loadProfile(self, profile, applyProfile) |
62 | |
63 | self.animationOffset = profile:getNumber("animationOffset", self.animationOffset) |
64 | self.animationFrames = profile:getNumber("animationFrames", self.animationFrames) |
65 | self.animationSpeed = profile:getNumber("animationSpeed", self.animationSpeed) |
66 | |
67 | local animationUVOffset = profile:getValue("animationUVOffset") |
68 | if animationUVOffset ~= nil then |
69 | animationUVOffset = GuiUtils.getNormalizedValues(animationUVOffset, self.imageSize) |
70 | self.animationUVOffset = animationUVOffset[1] |
71 | end |
72 | end |
new
DescriptionDefinitionnew()Code
23 | function AnimationElement:new(target, custom_mt) |
24 | local self = BitmapElement:new(target, custom_mt or AnimationElement_mt) |
25 | |
26 | self.animationOffset = -1 |
27 | self.animationFrames = 8 |
28 | self.animationTimer = 0 |
29 | self.animationSpeed = 120 |
30 | self.animationFrameSize = 0 |
31 | self.animationStartPos = 0 |
32 | self.animationUVOffset = 0 |
33 | |
34 | return self |
35 | end |
setAnimationData
DescriptionDefinitionsetAnimationData()Code
115 | function AnimationElement:setAnimationData() |
116 | if self.overlay ~= nil then |
117 | local uvs = GuiOverlay.getOverlayUVs(self.overlay, self:getOverlayState()) |
118 | self.animationFrameSize = ((uvs[5]-uvs[1]- self.animationUVOffset*(self.animationFrames-1)) / self.animationFrames) |
119 | self.animationStartPos = uvs[1] |
120 | self:updateAnimationUVs() |
121 | end |
122 | end |
update
DescriptionDefinitionupdate()Code
92 | function AnimationElement:update(dt) |
93 | AnimationElement:superClass().update(self, dt) |
94 | |
95 | self.animationTimer = self.animationTimer - dt |
96 | if self.animationTimer < 0 then |
97 | self.animationTimer = self.animationSpeed |
98 | self.animationOffset = self.animationOffset + 1 |
99 | if self.animationOffset > self.animationFrames - 1 then |
100 | self.animationOffset = 0 |
101 | end |
102 | self:updateAnimationUVs() |
103 | end |
104 | end |
updateAnimationUVs
DescriptionDefinitionupdateAnimationUVs()Code
108 | function AnimationElement:updateAnimationUVs() |
109 | local frameOffset = self.animationStartPos + (self.animationFrameSize+self.animationUVOffset)*self.animationOffset |
110 | self:setImageUVs(nil, frameOffset, nil, frameOffset, nil, frameOffset+self.animationFrameSize, nil, frameOffset+self.animationFrameSize, nil) |
111 | end |