Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ColorPickButtonElement
- ConstructionScreen
- ContextActionDisplay
- ControlBarDisplay
- DialogElement
- DynamicFadedBitmapElement
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GameInfoDisplayMobile
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiTopDownCursor
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDSliderElement
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InfoDisplay
- InfoHUDBox
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputGlyphElementUI
- InputHelpDisplay
- KeyValueInfoHUDBox
- ListElement
- ListItemElement
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PictureElement
- PlatformIconElement
- PlayerControlPadDisplay
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- ScrollingLayoutElement
- SettingsModel
- SideNotification
- SideNotificationMobile
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- SpeedSliderDisplay
- StatusBar
- SteeringSliderDisplay
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TerrainLayerElement
- TextBackdropElement
- TextElement
- TextInputElement
- ThreePartBitmapElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VariableWorkWidthHUDExten...
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- WardrobeScreen
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
HUDTextDisplay
DescriptionHUD text display. Displays a formatted single-line text with optional animations.Parent
HUDDisplayElementFunctions
draw
DescriptionDraw the text.Definition
draw()Code
142 | function HUDTextDisplay:draw() |
143 | setTextBold(self.textBold) |
144 | local posX, posY = self:getPosition() |
145 | setTextAlignment(self.textAlignment) |
146 | |
147 | setTextWrapWidth(0.9) |
148 | |
149 | if self.hasShadow then |
150 | local offset = self.screenTextSize * HUDTextDisplay.SHADOW_OFFSET_FACTOR |
151 | local r, g, b, a = unpack(self.shadowColor) |
152 | setTextColor(r, g, b, a * self.overlay.a) |
153 | renderText(posX + offset, posY - offset, self.screenTextSize, self.text) |
154 | end |
155 | |
156 | local r, g, b, a = unpack(self.textColor) |
157 | setTextColor(r, g, b, a * self.overlay.a) |
158 | renderText(posX, posY, self.screenTextSize, self.text) |
159 | |
160 | setTextAlignment(RenderText.ALIGN_LEFT) |
161 | setTextWrapWidth(0) |
162 | setTextBold(false) |
163 | setTextColor(1, 1, 1, 1) |
164 | end |
new
DescriptionCreate a new HUDTextDisplay.Definition
new(float posX, float posY, float textSize, int textAlignment, table textColor, bool textBool)Arguments
float | posX | Screen space X position of the text display |
float | posY | Screen space Y position of the text display |
float | textSize | Text size in reference resolution pixels |
int | textAlignment | Text alignment as one of RenderText.[ALIGN_LEFT | ALIGN_CENTER | ALIGN_RIGHT] |
table | textColor | Text display color as an array {r, g, b, a} |
bool | textBool | If true, will render the text in bold |
table | HUDTextDisplay | instance |
27 | function HUDTextDisplay.new(posX, posY, textSize, textAlignment, textColor, textBold) |
28 | local backgroundOverlay = Overlay.new(nil, 0, 0, 0, 0) |
29 | backgroundOverlay:setColor(1, 1, 1, 1) |
30 | local self = HUDTextDisplay:superClass().new(backgroundOverlay, nil, HUDTextDisplay_mt) |
31 | |
32 | self.initialPosX = posX |
33 | self.initialPosY = posY |
34 | self.text = "" -- must be set in a separate call which will correctly set up boundaries and position |
35 | self.textSize = textSize or 0 |
36 | self.screenTextSize = self:scalePixelToScreenHeight(self.textSize) |
37 | self.textAlignment = textAlignment or RenderText.ALIGN_LEFT |
38 | self.textColor = textColor or {1, 1, 1, 1} |
39 | self.textBold = textBold or false |
40 | |
41 | self.hasShadow = false |
42 | self.shadowColor = {0, 0, 0, 1} |
43 | |
44 | return self |
45 | end |
setAlpha
DescriptionSet the global alpha value for this text display. The alpha value will be multiplied with any text color alpha channel value.Definition
setAlpha()Code
101 | function HUDTextDisplay:setAlpha(alpha) |
102 | self:setColor(nil, nil, nil, alpha) |
103 | end |
setAnimation
DescriptionSet an animation tween (sequence) for this text display. The animation can be played when calling HUDTextDisplay:setVisible() with the "animate" paramter set to true.Definition
setAnimation()Code
127 | function HUDTextDisplay:setAnimation(animationTween) |
128 | self:storeOriginalPosition() |
129 | self.animation = animationTween or TweenSequence.NO_SEQUENCE |
130 | end |
setScale
DescriptionSet the text display UI scale.Definition
setScale()Code
73 | function HUDTextDisplay:setScale(uiScale) |
74 | HUDTextDisplay:superClass().setScale(self, uiScale) |
75 | |
76 | self.screenTextSize = self:scalePixelToScreenHeight(self.textSize) |
77 | end |
setText
DescriptionSet the text to display.Definition
setText(string text, float textSize, int textAlignment, table textColor, bool textBool)Arguments
string | text | Display text |
float | textSize | Text size in reference resolution pixels |
int | textAlignment | Text alignment as one of RenderText.[ALIGN_LEFT | ALIGN_CENTER | ALIGN_RIGHT] |
table | textColor | Text display color as an array {r, g, b, a} |
bool | textBool | If true, will render the text in bold |
54 | function HUDTextDisplay:setText(text, textSize, textAlignment, textColor, textBold) |
55 | -- assign values with initial values as defaults |
56 | self.text = text or self.text |
57 | self.textSize = textSize or self.textSize |
58 | self.screenTextSize = self:scalePixelToScreenHeight(self.textSize) |
59 | self.textAlignment = textAlignment or self.textAlignment |
60 | self.textColor = textColor or self.textColor |
61 | self.textBold = textBold or self.textBold |
62 | |
63 | local width, height = getTextWidth(self.screenTextSize, self.text), getTextHeight(self.screenTextSize, self.text) |
64 | self:setDimension(width, height) |
65 | |
66 | local posX, posY = self.initialPosX, self.initialPosY |
67 | |
68 | self:setPosition(posX, posY) |
69 | end |
setTextColorChannels
DescriptionSet the text color by channels. Use for dynamic changes and animation.Definition
setTextColorChannels()Code
108 | function HUDTextDisplay:setTextColorChannels(r, g, b, a) |
109 | self.textColor[1] = r |
110 | self.textColor[2] = g |
111 | self.textColor[3] = b |
112 | self.textColor[4] = a |
113 | end |
setTextShadow
DescriptionSet the text shadow state.Definition
setTextShadow(bool isShadowEnabled, table shadowColor)Arguments
bool | isShadowEnabled | If true, will cause a shadow to be rendered under the text |
table | shadowColor | Shadow text color as an array {r, g, b, a} |
119 | function HUDTextDisplay:setTextShadow(isShadowEnabled, shadowColor) |
120 | self.hasShadow = isShadowEnabled or self.hasShadow |
121 | self.shadowColor = shadowColor or self.shadowColor |
122 | end |
setVisible
DescriptionSet this element's visibility.Definition
setVisible(bool isVisible, bool animate)Arguments
bool | isVisible | Visibility state |
bool | animate | If true, will play the currently set animation on becoming visible or and reset it when necessary. |
83 | function HUDTextDisplay:setVisible(isVisible, animate) |
84 | -- shadow parent behavior which includes repositioning |
85 | HUDElement.setVisible(self, isVisible) |
86 | |
87 | if animate then |
88 | if not isVisible or not self.animation:getFinished() then |
89 | self.animation:reset() |
90 | end |
91 | |
92 | if isVisible then |
93 | self.animation:start() |
94 | end |
95 | end |
96 | end |
update
DescriptionUpdate this element's state.Definition
update()Code
134 | function HUDTextDisplay:update(dt) |
135 | if self:getVisible() then |
136 | HUDTextDisplay:superClass().update(self, dt) |
137 | end |
138 | end |