Component_MessageTextRenderer Class
A text-renderer component to render an animated and interactive message text using dimensions of the game object's destination-rectangle. The message is displayed using a sprite for each line instead of drawing to the game object's bitmap object.
Item Index
Methods
- addCustomObject
- addCustomObject
- analyzeControlToken
- calculateDuration
- calculateDurationForLine
- calculateDurationForToken
- calculateMaxLines
- clear
- clearAllSprites
- clearSprites
- continue
- createBitmap
- createSprite
- createSprites
- createToken
- dispose
- drawControlToken
- drawFormattedText
- drawFormattedTextImmediately
- drawLineContent
- drawNext
- executeBatch
- finish
- instantSkip
- isBatched
- isBatchInProgress
- newLine
- nextChar
- onDataBundleRestore.
- processControlToken
- processToken
- restore
- setup
- setupEventHandlers
- start
- toDataBundle
- update
- updateCaretPosition
- updateLineWriting
Properties
- allSprites
- caretPosition
- charIndex
- currentLine
- currentLineHeight
- currentSprite
- currentX
- currentY
- customObjects
- customObjects
- drawImmediately
- isRunning
- isWaiting
- line
- lines
- lineSpacing
- minLineHeight
- onBatchDisappear
- onLinkClick
- padding
- speed
- sprites
- waitAtEnd
- waitAtEndTime
- waitCounter
- waitForKey
- wordWrap
Methods
addCustomObject
-
object
Clears the list of custom game objects. All game objects are disposed and removed from the scene.
Parameters:
-
object
ObjectThe game object to add.
addCustomObject
-
object
Adds a game object to the message which is alive until the message is erased. Can be used to display animationed-icons, etc. in a message.
Parameters:
-
object
ObjectThe game object to add.
analyzeControlToken
-
token
Measures a control-token. If a token produces a visual result like displaying an icon then it must return the size taken by the visual result. If the token has no visual result, null must be returned. This method is called for every token when the message is initialized.
This method is not called while the message is running. For that case, see processControlToken method which is called for every token while the message is running.
Parameters:
-
token
Object- A control-token.
Returns:
The size of the area taken by the visual result of the token or null if the token has no visual result.
calculateDuration
()
Number
Calculates the duration(in frames) the message-renderer needs to display the message.
Returns:
The duration in frames.
calculateDurationForLine
-
line
Calculates the duration(in frames) the message-renderer needs to display the specified line.
Parameters:
-
line
gs.RendererTextLineThe line to calculate the duration for.
Returns:
The duration in frames.
calculateDurationForToken
-
token
Calculates the duration(in frames) the message-renderer needs to process the specified token.
Parameters:
-
token
String | Object- The token.
Returns:
The duration in frames.
calculateMaxLines
-
lines
Calculates the maximum of lines which can be displayed in one message.
Parameters:
-
lines
Array- An array of line-objects.
Returns:
The number of displayable lines.
clear
()
Clears/Resets the text-renderer.
clearAllSprites
()
Clears/Disposes all sprites used to display the text-lines/parts.
clearSprites
()
Clears/Disposes the sprites used to display the text-lines/parts of the current/last message.
continue
()
Continues message-processing if currently waiting.
createBitmap
-
line
Creates the bitmap for a specified line-object.
Parameters:
-
line
Object- A line-object.
Returns:
A newly created bitmap containing the line-text.
createSprite
-
line
Creates the sprite for a specified line-object.
Parameters:
-
line
Object- A line-object.
Returns:
A newly created sprite object containing the line-text as bitmap.
createSprites
-
lines
Creates the sprites for a specified array of line-objects.
Parameters:
-
lines
Array- An array of line-objects.
Returns:
An array of sprites.
createToken
-
code
-
value
Creates a token-object for a specified text-code.
Parameters:
-
code
String- The code/type of the text-code.
-
value
String- The value of the text-code.
Returns:
The token-object.
dispose
()
Disposes the message text-renderer and all sprites used to display the message.
drawControlToken
-
token
-
bitmap
-
offset
-
length
Draws the visual result of a token, like an icon for example, to the specified bitmap. This method is called for every token when the message is initialized and the sprites for each text-line are created.
This method is not called while the message is running. For that case, see processControlToken method which is called for every token while the message is running.
Parameters:
-
token
Object- A control-token.
-
bitmap
gs.Bitmap- The bitmap used for the current text-line. Can be used to draw something on it like an icon, etc.
-
offset
Number- An x-offset for the draw-routine.
-
length
Number- Determines how many characters of the token should be drawn. Can be ignored for tokens not drawing any characters.
drawFormattedText
-
x
-
y
-
width
-
height
-
text
-
wordWrap
Starts the rendering-process for the message.
Parameters:
-
x
Number- The x-coordinate of the text's position.
-
y
Number- The y-coordinate of the text's position.
-
width
Number- Deprecated. Can be null.
-
height
Number- Deprecated. Can be null.
-
text
String- The text to draw.
-
wordWrap
Boolean- If wordWrap is set to true, line-breaks are automatically created.
drawFormattedTextImmediately
-
x
-
y
-
width
-
height
-
text
-
wordWrap
Displays a formatted text immediately without any delays or animations. The Component_TextRenderer.drawFormattedText method from the base-class cannot be used here because it would render to the game object's bitmap object while this method is rendering to the sprites.
Parameters:
-
x
Number- The x-coordinate of the text's position.
-
y
Number- The y-coordinate of the text's position.
-
width
Number- Deprecated. Can be null.
-
height
Number- Deprecated. Can be null.
-
text
String- The text to draw.
-
wordWrap
Boolean- If wordWrap is set to true, line-breaks are automatically created.
drawLineContent
-
line
-
bitmap
-
length
Draws the line's content on the specified bitmap.
Parameters:
-
line
Object- A line-object which should be drawn on the bitmap.
-
bitmap
gs.Bitmap- The bitmap to draw the line's content on.
-
length
Number- Determines how many characters of the specified line should be drawn. You can specify -1 to draw all characters.
drawNext
()
Displays the character or processes the next control-token.
executeBatch
()
Starts displaying the next page of text if a message is too long to fit into one message box.
finish
()
Finishes the message. Depending on the message configuration, the message text-renderer will now wait for a user-action or a certain amount of time.
instantSkip
()
Skips the current message and finishes the message-processing immediately. The message tokens are processed but not rendered.
isBatched
()
Indicates if its a batched messages.
Returns:
If true it is a batched message. Otherwise false.
isBatchInProgress
()
Indicates if the batch is still in progress and not done.
Returns:
If true the batched message is still not done. Otherwise false
newLine
()
Starts a new line.
nextChar
()
private
Processes the next character/token of the message.
onDataBundleRestore.
-
Object
-
gs.ObjectCodecContext
Called if this object instance is restored from a data-bundle. It can be used re-assign event-handler, anonymous functions, etc.
Parameters:
-
Object
Objectdata - The data-bundle
-
gs.ObjectCodecContext
Objectcontext - The codec-context.
processControlToken
-
token
-
formattingOnly
Processes a control-token. A control-token is a token which influences the text-rendering like changing the fonts color, size or style. Changes will be automatically applied to the game object's font.
For message text-renderer, a few additional control-tokens like speed-change, waiting, etc. needs to be processed here.
This method is called for each token while the message is initialized and also while the message is running. See formattingOnly parameter.
Parameters:
-
token
Object- A control-token.
-
formattingOnly
Boolean- If true the message is initializing right now and only format-tokens should be processed which is necessary for the message to calculated sizes correctly.
Returns:
A new token which is processed next or null.
processToken
()
Processes the current token.
restore
-
bundle
Restores the message text-renderer's state from a data-bundle.
Parameters:
-
bundle
Object- A data-bundle containing message text-renderer state.
setup
()
Sets up the renderer. Registers necessary event handlers.
setupEventHandlers
()
Adds event-handlers for mouse/touch events
start
()
protected
Starts the message-rendering process.
toDataBundle
()
Object
Serializes the message text-renderer into a data-bundle.
Returns:
A data-bundle.
update
()
Updates the text-renderer.
updateCaretPosition
()
Returns the position of the caret in pixels. The caret is like an invisible cursor pointing to the x/y coordinates of the last rendered character of the message. That position can be used to display a waiting- or processing-animation for example.
updateLineWriting
()
private
Updates the line writing.
Properties
allSprites
gs.Sprite
protected
An array containing all sprites of all messages. In NVL mode a page can contain multiple messages.
caretPosition
gs.Point
Position of the message caret. The caret is like an invisible cursor pointing to the x/y coordinates of the last rendered character of the message. That position can be used to display a waiting- or processing-animation for example.
charIndex
Number
Index of the current character to draw.
currentLine
Number
protected
The line currently rendered.
currentLineHeight
Number
protected
The height of the line currently rendered.
currentSprite
gs.Sprite
The current sprites used to display the current text-line/part.
currentX
Number
The current x-coordinate of the caret/cursor.
currentY
Number
The current y-coordinate of the caret/cursor.
customObjects
Object
A hashtable/dictionary object to store custom-data useful like for token-processing. The data must be serializable.
customObjects
gs.Object_Base
Custom game objects which are alive until the current message is erased. Can be used to display animated icons, etc.
drawImmediately
Boolean
Indicates if the message should be rendered immedialtely without any animation or delay.
isRunning
Boolean
Indicates that the a message is currently in progress.
isWaiting
Boolean
Indicates if the message-renderer is currently waiting like for a user-action.
line
Number
The line currently rendered.
lines
gs.TextRendererLine
An array containing all line-objects of the current message.
lineSpacing
Number
The spacing between text lines in pixels.
minLineHeight
Number
The minimum height of the line currently rendered. If 0, the measured height of the line will be used.
onBatchDisappear
Function
A callback function called if a batched messsage has been faded out. It triggers the execution of the next message.
onLinkClick
Function
A callback function called if the player clicks on a non-stylable link (LK text-code) to trigger the specified common event.
padding
Number
The left and right padding per line.
speed
Number
Speed of the message-drawing. The smaller the value, the faster the message is displayed.
sprites
gs.Sprite
protected
An array containing all sprites of the current message.
waitAtEnd
Boolean
Indicates if the message should wait for a user-action or a certain amount of time before finishing.
waitAtEndTime
Number
The number of frames to wait before finishing a message. before finishing.
waitCounter
Number
Number of frames the message-renderer should wait before continue.
waitForKey
Boolean
Indicates if the message-renderer is currently waiting for a key-press or mouse/touch action.
wordWrap
Boolean
Indicates if auto word-wrap should be used. Default is true