• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Text Placement

Status
Not open for further replies.
Level 17
Joined
Nov 18, 2008
Messages
1,538
How do I make it so text messages appear in different parts of the screen. For example, on the bottom like subtitles, or straight in the middle like a title.
 
Level 14
Joined
Nov 23, 2008
Messages
187
Use x and y parameters of these functions to show text messages in specified positions:

JASS:
native DisplayTextToPlayer      takes player toPlayer, real x, real y, string message returns nothing
native DisplayTimedTextToPlayer takes player toPlayer, real x, real y, real duration, string message returns nothing

x is text position by X (range of values is [0.0 .. 0.825]);
y is text position by Y (range of values is [0.0 .. 0.7]);
Bigger values will show the text out of game screen.
 
Level 14
Joined
Nov 23, 2008
Messages
187
When x=0 and y=0, message will be displayed as usual (near the left bottom corner of game screen).

Note that text is displayed with left side justify. So if message "Have you cake?" will be centered on the game screen (via x and y), other message "Have you cake and eat it too?" with the same coordinates will not.

Well, I think, some examples would be easier to understand:

JASS:
// this will display auto-timed message to red player right under the game clocks
call DisplayTextToPlayer(Player(0), 0.3, 0.65, "Have you an apple cake?")

// this will display message to blue player for 5 sec at the center of the gamescreen 
call DisplayTimedTextToPlayer(Player(1), 0.365, 0.27, 5.0, "FIGHT!")

// this will display message to all players for 10 minutes near the food usage window
local integer i = 0
loop
  call DisplayTimedTextToPlayer(Player(i), 0.65, 0.7, 600.0, "Food usage")
  set i = i + 1
  exitwhen i > 11
endloop
 
Level 14
Joined
Nov 23, 2008
Messages
187
Just copy (or write by yourself) the function into custom script action and setup parameters:

JASS:
call DisplayTextToPlayer(Player(0), 0.0, 0.0, "<your text>")

For example:

  • Custom script: call DisplayTextToPlayer(Player(0), 0.3, 0.65, "Have you an apple cake?")
 
Level 14
Joined
Nov 23, 2008
Messages
187
Well, Warcraft is written on C++. Jass natives are naturally c++ functions, with their pros and cons. So we can use some escape sequences to make such things.

I noticed that when I started learning Jass 2 years ago. I thought why users should type double backslash instead of one, and realized that the same notation uses C++.

I tested some sequences (with JNGP v5b) and got following results:
  • \a - beep sound - syntax error
  • \' - single quote - syntax error
  • \b - backspace - no effect
  • \t - tabulation - no effect
  • \" - double quote - works
  • \n - new line - works
  • \\ - backslash - works
However, there is no need in \' sequence, we can just write ' character directly.
 
Level 12
Joined
Mar 16, 2006
Messages
992
Is there a way to find the resolution the player is using to find the center? Because I don't think you can find a true center without that.
 
Status
Not open for further replies.
Top