Difference between revisions of "Change Text Position"
(Created page with "{| class="ts" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | Change text Position || Definition...") |
|||
Line 5: | Line 5: | ||
| Change text Position || Definition || Various | | Change text Position || Definition || Various | ||
|} | |} | ||
+ | |||
This script sets (character or narration) text to a fixed position on screen. | This script sets (character or narration) text to a fixed position on screen. |
Revision as of 14:40, 28 August 2023
Name | Type | By |
---|---|---|
Change text Position | Definition | Various |
This script sets (character or narration) text to a fixed position on screen.
Instructions
Visionaire offers a function hook for changing the text position. You find some examples on how to implement it below, but the script you need depends on which texts you want to handle and where you want to place them.
Add one of the scripts to the Visionaire Studio Script Editor, set the script as a definition script and change it according to your needs.
Scripts
Basic setup
This basic example shows how to set up the hook function. It handles character and narrator texts.
-- Hook function
function txtPos(text)
-- Define the new text position
text.Position = {x = 300, y = 300}
-- Return true to tell the engine that the text position is handled by this hook function
return true
end
-- Register the hook function for the "setTextPosition" operation
registerHookFunction("setTextPosition", "txtPos")
Distinguish by owner
Query the owner of the text, if you want to set the text position only for texts spoken by a certain character.
function txtPos(text)
-- Only handle texts spoken by the character named "hero"
if text.Owner.name == "hero" then
text.Position = {x = 300, y = 300}
return true
end
-- Return false to let the engine ignore the hook function, if the "if" query wasn't met
return false
end
registerHookFunction("setTextPosition", "txtPos")
Change the query to handle all character texts or all narration texts.
-- Handle character texts only
if text.Owner.tableId == eCharacters then
...
-- Only handle narrator texts
if text.Owner.tableId == eGame then
...
Scrolling scenes
The text position is defined in relation to the scene, not the visible screen. So if your scene is larger than the game resolution (and thus scrollable), you have to take the current scroll position into account (this code also works if your scene equals the game resolution of course, because the scroll position is always [0,0] then).
function txtPos(text)
if text.Owner.tableId == eCharacters then
-- Define the new text position on the screen
text.Position = {x = 300 + game.ScrollPosition.x, y = 330 + game.ScrollPosition.y}
return true
end
return false
end
registerHookFunction("setTextPosition", "txtPos")
This will set the horizontal position to center. Make sure to set the text alignment to "center" in the game properties, too.
-- Set the text position horizontally centered
text.Position = {x = game.WindowResolution.x/2 + game.ScrollPosition.x, y = 300 + game.ScrollPosition.y}
...