Difference between revisions of "Change Text Position"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(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...")
 
 
(2 intermediate revisions by the same user not shown)
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.
Line 17: Line 18:
 
== Scripts ==
 
== Scripts ==
 
=== Basic setup ===
 
=== Basic setup ===
This basic example shows how to set up the hook function. It handles character and narrator texts.
+
This basic example shows how to set up the hook function. It handles character and narration texts.
  
 
<html><button id="button1" class="copybtn" onclick="CopyToClipboard('txt1')"></button></html>
 
<html><button id="button1" class="copybtn" onclick="CopyToClipboard('txt1')"></button></html>
Line 64: Line 65:
 
   ...
 
   ...
  
   -- Only handle narrator texts
+
   -- Only handle narration texts
 
   if text.Owner.tableId == eGame then
 
   if text.Owner.tableId == eGame then
 
   ...
 
   ...
Line 71: Line 72:
  
 
=== Scrolling scenes ===
 
=== 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).
+
The text position is defined in relation to the scene, not to 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).
  
 
<html><button id="button1" class="copybtn" onclick="CopyToClipboard('txt4')"></button></html>
 
<html><button id="button1" class="copybtn" onclick="CopyToClipboard('txt4')"></button></html>
Line 78: Line 79:
 
   if text.Owner.tableId == eCharacters then
 
   if text.Owner.tableId == eCharacters then
 
     -- Define the new text position on the screen
 
     -- Define the new text position on the screen
     text.Position = {x = 300 + game.ScrollPosition.x, y = 330 + game.ScrollPosition.y}
+
     text.Position = {x = 300 + game.ScrollPosition.x, y = 300 + game.ScrollPosition.y}
 
   
 
   
 
     return true
 
     return true

Latest revision as of 16:37, 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 narration 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 narration texts
  if text.Owner.tableId == eGame then
  ...


Scrolling scenes

The text position is defined in relation to the scene, not to 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 = 300 + 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}
  ...