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
HUDTextDisplay
DescriptionHUD text display. Displays a formatted single-line text with optional animations.Parent
HUDDisplayElementFunctions
draw
DescriptionDraw the text.Definition
draw()Code
147 | function HUDTextDisplay:draw() |
148 | setTextBold(self.textBold) |
149 | local posX, posY = self:getPosition() |
150 | -- NOTE: alignment is factored into background overlay position, use left alignment now |
151 | setTextAlignment(RenderText.ALIGN_LEFT) |
152 | |
153 | if self.hasShadow then |
154 | local offset = self.screenTextSize * HUDTextDisplay.SHADOW_OFFSET_FACTOR |
155 | local r, g, b, a = unpack(self.shadowColor) |
156 | setTextColor(r, g, b, a * self.overlay.a) |
157 | renderText(posX + offset, posY - offset, self.screenTextSize, self.text) |
158 | end |
159 | |
160 | local r, g, b, a = unpack(self.textColor) |
161 | setTextColor(r, g, b, a * self.overlay.a) |
162 | renderText(posX, posY, self.screenTextSize, self.text) |
163 | |
164 | setTextBold(false) |
165 | setTextColor(1, 1, 1, 1) |
166 | 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(HUDTextDisplay_mt, backgroundOverlay, nil) |
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
106 | function HUDTextDisplay:setAlpha(alpha) |
107 | self:setColor(nil, nil, nil, alpha) |
108 | 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
132 | function HUDTextDisplay:setAnimation(animationTween) |
133 | self:storeOriginalPosition() |
134 | self.animation = animationTween or TweenSequence.NO_SEQUENCE |
135 | end |
setScale
DescriptionSet the text display UI scale.Definition
setScale()Code
78 | function HUDTextDisplay:setScale(uiScale) |
79 | HUDTextDisplay:superClass().setScale(self, uiScale) |
80 | |
81 | self.screenTextSize = self:scalePixelToScreenHeight(self.textSize) |
82 | 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 | if self.textAlignment == RenderText.ALIGN_CENTER then |
68 | posX = posX - width * 0.5 |
69 | elseif self.textAlignment == RenderText.ALIGN_RIGHT then |
70 | posX = posX - width |
71 | end |
72 | |
73 | self:setPosition(posX, posY) |
74 | end |
setTextColorChannels
DescriptionSet the text color by channels. Use for dynamic changes and animation.Definition
setTextColorChannels()Code
113 | function HUDTextDisplay:setTextColorChannels(r, g, b, a) |
114 | self.textColor[1] = r |
115 | self.textColor[2] = g |
116 | self.textColor[3] = b |
117 | self.textColor[4] = a |
118 | 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} |
124 | function HUDTextDisplay:setTextShadow(isShadowEnabled, shadowColor) |
125 | self.hasShadow = isShadowEnabled or self.hasShadow |
126 | self.shadowColor = shadowColor or self.shadowColor |
127 | 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. |
88 | function HUDTextDisplay:setVisible(isVisible, animate) |
89 | -- shadow parent behavior which includes repositioning |
90 | HUDElement.setVisible(self, isVisible) |
91 | |
92 | if animate then |
93 | if not isVisible or not self.animation:getFinished() then |
94 | self.animation:reset() |
95 | end |
96 | |
97 | if isVisible then |
98 | self.animation:start() |
99 | end |
100 | end |
101 | end |
update
DescriptionUpdate this element's state.Definition
update()Code
139 | function HUDTextDisplay:update(dt) |
140 | if self:getVisible() then |
141 | HUDTextDisplay:superClass().update(self, dt) |
142 | end |
143 | end |