TextItemSetPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(!&"*&!"!)$"! silly mistake)
(Remove spaces)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Incomplete]]
__NOTOC__
 
{{Server function}}
__NOTOC__
This function allows the setting of the position of a text item.
This function allows the setting of the position of a text item


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool textItemSetPosition ( textitem textitem, float x, float y )            
bool textItemSetPosition ( textitem theTextItem, float x, float y )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''textitem:''' The text item you wish to change the position of.
*'''theTextItem:''' The text item that you want to move
*'''x:''' A floating point number between 0.0 and 1.0 indicating how far across the screen the text should be shown, as a percentage of the width, from the left hand side.
*'''x:''' A floating point number between 0.0 and 1.0 indicating how far across the screen the text should be shown, as a percentage of the width, from the left hand side.
*'''y:''' A floating point number between 0.0 and 1.0 indicating how far down the screen the text should be shown, as a percentage of the height, from the top.
*'''y:''' A floating point number between 0.0 and 1.0 indicating how far down the screen the text should be shown, as a percentage of the height, from the top.
Line 18: Line 17:


==Example==  
==Example==  
This example creates a text item 'myTextItem' only if the text item 'otherTextItem' is not in the same position, to prevent overlap. If it is in the same position, then it moves it down.
This example creates a text item 'myTextItem' only if the text item 'otherTextItem' is not in the same position, to prevent overlap. If it is in the same position, then it moves it down.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
myDisplay = textCreateDisplay () --created display
myDisplay = textCreateDisplay ( )                   -- create a text display
textDisplayAddObserver ( myDisplay, myPlayer ) --made display visible to player
textDisplayAddObserver ( myDisplay, myPlayer )     -- make it visible to the player
x,y = textItemGetPosition ( otherTextItem ) --get the position of 'otherTextItem'
x,y = textItemGetPosition ( otherTextItem )         -- get the position of 'otherTextItem'
if ( x == 0.5 ) and ( y == 0.5 ) then --if the x and y of the text item are in the middle
if ( x == 0.5 ) and ( y == 0.5 ) then               -- if the x and y of the text item are in the middle
     textItemSetPosition ( otherTextItem, 0.5, 0.6 ) --move the otherTextItem down
     textItemSetPosition ( otherTextItem, 0.5, 0.6 ) -- move otherTextItem down
end  
end  
myTextItem = textCreateTextItem ( "Hello world!", 0.5, 0.5 ) --and create a new item for the display in the middle saying "Hello world" in the middle
myTextItem = textCreateTextItem ( "Hello world!", 0.5, 0.5 ) -- create a new text item in the middle saying "Hello world"
textDisplayAddText ( myDisplay, myTextItem ) --and add it to the text display
textDisplayAddText ( myDisplay, myTextItem )       -- and add it to the text display
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Text functions}}
{{Text functions}}

Latest revision as of 21:14, 29 October 2023

This function allows the setting of the position of a text item.

Syntax

bool textItemSetPosition ( textitem theTextItem, float x, float y )

Required Arguments

  • theTextItem: The text item that you want to move
  • x: A floating point number between 0.0 and 1.0 indicating how far across the screen the text should be shown, as a percentage of the width, from the left hand side.
  • y: A floating point number between 0.0 and 1.0 indicating how far down the screen the text should be shown, as a percentage of the height, from the top.

Returns

Returns true if the position was successfully set, false otherwise.

Example

This example creates a text item 'myTextItem' only if the text item 'otherTextItem' is not in the same position, to prevent overlap. If it is in the same position, then it moves it down.

myDisplay = textCreateDisplay ( )                    -- create a text display
textDisplayAddObserver ( myDisplay, myPlayer )      -- make it visible to the player
x,y = textItemGetPosition ( otherTextItem )         -- get the position of 'otherTextItem'
if ( x == 0.5 ) and ( y == 0.5 ) then               -- if the x and y of the text item are in the middle
    textItemSetPosition ( otherTextItem, 0.5, 0.6 ) -- move otherTextItem down
end 
myTextItem = textCreateTextItem ( "Hello world!", 0.5, 0.5 ) -- create a new text item in the middle saying "Hello world"
textDisplayAddText ( myDisplay, myTextItem )        -- and add it to the text display

See Also