HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Displaying text on the screen  (Read 954 times)

Joseph-B

  • General Accounts
  • *
  • Posts: 5
    • View Profile
Displaying text on the screen
« on: Feb 06, 17, 06:47:41 AM »

Hi all,

I'm not too sure if i'm posting this in the correct place - I apologise if I'm not!

I've looked all over the HeroEngine Wiki and through these forums, and I have found many GUI tutorials such as opening a GUI window, however I have not found any information on how to simply display text on the screen.

What would be the best way to go about doing this - or are there any resources with an explanation/documentation on how to do this?

Many thanks!

Joseph.
Logged

GlorianLanTarini

  • General Accounts
  • *
  • Posts: 148
    • View Profile
Re: Displaying text on the screen
« Reply #1 on: Feb 06, 17, 10:49:11 AM »

Hi, Joseph.

There is several ways to did it. But most simple and don't require any additional action is next:

Code: [Select]
new_panel as NodeRef of Class GUIPanel = CreateNodeFromPrototype("_panel")       
newLabel as NodeRef of Class GUILabel = CreateNodeFromPrototype("_label")
viewport_size as Vector3 = GetViewPortSize()
new_panel.name = "SampleMessagePanel"
new_panel.layer = "game"
new_panel.size.x = viewport_size.x
new_panel.size.y = viewport_size.y
new_panel.ignoreMouseEvents = true
add back newLabel to new_panel.children
new_panel.defaultStatePresentation.color.a = 0.0
new_panel.build = true
newLabel.justification = CENTER
newLabel.dockMode = FILL
newLabel.text = "JUST ANOTHER MESSAGE"
newLabel.displayfont = JUMBO
newLabel.dropShadowAlpha = 1.0
newLabel.defaultStatePresentation.color.r = 1
newLabel.build = true

This code will show you message at center of the screen. All what you need to do is decide how to invoke it.

When you don't need this message any more, just call this code:

Code: [Select]
new_panel as NodeRef of Class GUIPanel = FindGUIControlByName(0,"game.SampleMessagePanel")
DestroyNode( new_panel )
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Displaying text on the screen
« Reply #2 on: Feb 06, 17, 10:51:57 AM »

Gloria beat me to it, but here are some more details:

Yeah there is a control called _label that is for displaying text. Knowing that all GUI controls are in fact prototypes of GUI classes, the simplest form you could do something in code like create a label node:

Code: [Select]
myLabel as NodeRef of class GUILabel = CreateNodeFromPrototype("_label")
myLabel.build = true

The "build = true" line is very important.  That line causes the structure of the control to be built and any gui control created needs to have that put somewhere after it is created. If there are any child controls, they are not created until after build = true.

The GUILabel class has a field called "text" that defines what text it displays. There are also other properties such as defining the font to use and how it is justified, e.g. centered, left, right, etc.

Like all GUI controls, there are properties of position and size to determine the rectangular space it will occupy in its parent, which is the screen by default.

Make sure you store that label reference so you can later delete it or hide it.  Like all nodes, you can use DestroyNode() if you want to just get rid of it.

Note that for anything more complex, the GUI Editor is the preferred method for designing GUI's rather than trying to set every property in code.

See these pages for some more details:
http://hewiki.heroengine.com/wiki/GUI_Controls#GUILabel
http://hewiki.heroengine.com/wiki/GUI_Label_Markup
http://hewiki.heroengine.com/wiki/GUI_Editor
« Last Edit: Feb 06, 17, 10:53:47 AM by FI-ScottZ »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.