txt node

Summary

The txt node displays wrapped text.

For more information see the XML reference entry for txt.

Constructor

txt.new( [id] )

The parameter id is optional. If specified the node will be given this id.

Example C.89. Use of txt constructor

<scene>
	<script type="text/x-lua">

		-- create a new txt node, add some text then add it to the scene
		mytxt = txt.new()
		mytxt:setText("Hello world, prepare to be augmented.")
		scene:appendNode(mytxt)
		
	</script>
	
</scene>

Functions

val node:getHAlignment()

Returns the horizontal alignment of the text displayed by the node. The return value will be one of the following values:

  • txt.ALIGN_LEFT

  • txt.ALIGN_HCENTER

  • txt.ALIGN_RIGHT

Example C.90. Use of getHAlignment

<scene>
	<script type="text/x-lua">
		
		mytxt = scene:getById("mytxt")
		halign = mytxt:getHAlignment()
		
		if halign == txt.ALIGN_LEFT
			-- mytxt is left-aligned
		elseif halign == txt.ALIGN_HCENTER
			-- mytxt is center-aligned
		elseif halign == txt.ALIGN_RIGHT
			-- mytext is right-aligned
		end
		
	</script>
	
	<txt id="mytxt">Hello world, prepare to be augmented.</txt>
	
</scene>


string node:getSize()

Returns a table of 2 values giving the size of the bounding box of the text - width and height.

Example C.91. Use of getSize

<scene>
	<script type="text/x-lua">
		
		mytxt = scene:getById("mytxt")
		
		mytxtsize = mytxt:getSize()
		w = mytxtsize[1]
		h = mytxtsize[2] 
		
	</script>
	
	<txt id="mytxt" size="1.5 2">Hello world, prepare to be augmented.</txt>
	
</scene>


string node:getText()

Returns the text of the txt node.

Example C.92. Use of getText

<scene>
	<script type="text/x-lua">
		
		mytxt = scene:getById("mytxt")
		mytxtstring = mytxt:getText()
		
		-- mytxtstring now reads "Hello world, prepare to be augmented."
		
	</script>
	
	<txt id="mytxt" size="1 1">Hello world, prepare to be augmented.</txt>
	
</scene>


val node:getVAlignment()

Returns the vertical alignment of the text displayed by the node. The return value will be one of the following values:

  • txt.ALIGN_TOP

  • txt.ALIGN_VCENTER

  • txt.ALIGN_BOTTOM

Example C.93. Use of getVAlignment

<scene>
	<script type="text/x-lua">
		
		mytxt = scene:getById("mytxt")
		valign = mytxt:getVAlignment()
		
		if valign == txt.ALIGN_TOP
			-- mytxt is aligned to the top
		elseif valign == txt.ALIGN_VCENTER
			-- mytxt is vertically centered
		elseif valign == txt.ALIGN_BOTTOM
			-- mytext is aligned to the bottom
		end
		
	</script>
	
	<txt id="mytxt">Hello world, prepare to be augmented.</txt>
	
</scene>


node:setHAlignment( halign )

Sets the horizontal alignment of the text displayed by the node. The parameter must be one of the following values:

  • txt.ALIGN_LEFT

  • txt.ALIGN_HCENTER

  • txt.ALIGN_RIGHT

Example C.94. Use of setHAlignment

<scene>
	<script type="text/x-lua">
		
		mytxt = scene:getById("mytxt")
		mytxt:setHAlignment(txt.ALIGN_HCENTER)
		
	</script>
	
	<txt id="mytxt">Hello world, prepare to be augmented.</txt>
	
</scene>


node:setSize( new_size )

Sets the size of the bounding box for the text. Pass a 2-element table with entries { width, height }.

Example C.95. Use of setSize

<scene>
	<script type="text/x-lua">
		
		mytxt = scene:getById("mytxt")
		mytxt:setSize({1.5, 2})
		
	</script>
	
	<txt id="mytxt" size="1 1">Hello world, prepare to be augmented.</txt>
	
</scene>


node:setText( new_text )

Sets the text that is displayed by the node.

Example C.96. Use of setText

<scene>
	<script type="text/x-lua">
		
		mytxt = scene:getById("mytxt")
		mytxt:setText("Final text")
		
	</script>
	
	<txt id="mytxt">Initial text</txt>
	
</scene>


node:setVAlignment( valign )

Sets the vertical alignment of the text displayed by the node. The parameter must be one of the following values:

  • txt.ALIGN_TOP

  • txt.ALIGN_VCENTER

  • txt.ALIGN_BOTTOM

Example C.97. Use of setVAlignment

<scene>
	<script type="text/x-lua">
		
		mytxt = scene:getById("mytxt")
		mytxt:setVAlignment(txt.ALIGN_VCENTER)
		
	</script>
	
	<txt id="mytxt">Hello world, prepare to be augmented.</txt>
	
</scene>


Functions common to nodes that may contain events

node:setEvent( event_type , event )

Set the event of the type specified to the event node provided.

Example C.98. Use of setEvent

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		
		myevent = event.new()
		-- OMITTED add actions to myevent
		
		myplane:setEvent("onclickdown", myevent)
		
	</script>
	
	<object id="myplane" type="primitives://plane.aro"/>
	
</scene>


node:triggerEvent( event_type )

Triggers the event type specified. This function has no effect in the case that there is no event associated with the event type specified.

Example C.99. Use of triggerEvent

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		
		myplane:triggerEvent("onclickdown")
		
	</script>
	
	<object id="myplane" type="primitives://plane.aro">
	
		<event type="onclickdown">
			<!-- OMITTED add actions -->
		</event>
	</object>
	
</scene>


Functions common to transformable nodes

pos graphnode:getPosition()

Returns a table of 3 values - x, y, and z.

Example C.100. Use of getPosition

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		pos = myplace:getPosition()
		x = pos[1]
		y = pos[2]
		z = pos[3]
		
	</script>
	<object id="myplane" type="primitives://plane.aro" position="1.2 -0.2 0.1"/>
</scene>


rot graphnode:getRotation()

Returns a table of 3 values - yaw, pitch and roll, in degrees.

Example C.101. Use of getRotation

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		rot = myplace:getRotation()
		yaw = rot[1]
		pitch = rot[2]
		roll = rot[3]
		
	</script>
	<object id="myplane" type="primitives://plane.aro" rotation="90 240 45"/>
</scene>


sca graphnode:getScale()

Returns a table of 3 values - x-scale, y-scale and z-scale.

Example C.102. Use of getScale

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		scale = myplace:getScale()
		x = scale[1]
		y = scale[2]
		z = scale[3]
		
	</script>
	<object id="myplane" type="primitives://plane.aro" scale="0.5 0.4 1"/>
</scene>


boolean transformablenode:isBillboard()

Returns whether the node is billboarded (always faces the camera) or not.

boolean transformablenode:isFillDepthBuffer()

Returns true if the node fills the depth buffer during rendering; otherwise returns false.

transformablenode:setBillboard( true or false )

Pass true or false to indicate if node should be displayed in a billboard fashion (always facing the camera) or not.

transformablenode:setFillDepthBuffer( true or false )

Pass true or false to indicate if node should fill the depth buffer during rendering.

node:setPosition( pos )

Sets the position of the node. Pass a 3-element table with entries { x, y, z }.

Example C.103. Use of setPosition

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		
		--          x     y    z
		newpos = { 1.5, -0.2, 0.1 } 
		myplane:setPosition(newpos)
		
	</script>
	<object id="myplane" type="primitives://plane.aro"/>
</scene>


node:setScale( sca )

Sets the scale of the node. Pass a 3-element table with entries { x, y, z }.

Example C.104. Use of setScale

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		
		--            x     y    z
		newscale = { 1.5, -0.2, 0.1 } 
		myplane:setScale(newscale)
		
	</script>
	<object id="myplane" type="primitives://plane.aro"/>
</scene>


node:setRelativeTo( val )

Pass either transformablenode.PARENT, transformablenode.CAMERA or transformablenode.SCREEN to indicate whether the transformation properties (position, scale and rotation) of the node are relative to its parent node, to the screen, or to the camera. For more information see Viewport-relative content.

Example C.105. Use of setRelativeTo

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		 
		myplane:setRelativeTo(transformablenode.SCREEN)
		
	</script>
	<object id="myplane" type="primitives://plane.aro"/>
</scene>


node:setRotation( rot )

Sets the rotation of the node. Pass a 3-element table with entries { yaw, pitch, roll }, in degrees.

Example C.106. Use of setRotation

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		
		--         yaw  pitch  roll
		newrot = { 90,  140,   45 } 
		myplane:setRotation(newrot)
		
	</script>
	<object id="myplane" type="primitives://plane.aro"/>
</scene>


Functions common to nodes

col graphnode:getColor()

Returns a table of 4 values - red, green, blue and alpha (transparency) between 0.0 and 1.0.

Example C.107. Use of getColor

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		cols = myplace:getColor()
		red = cols[1]
		green = cols[2]
		blue = cols[3]
		alpha = cols[4]
		
	</script>
	<object id="myplane" type="primitives://plane.aro" color="0.5 1 1 0.75"/>
</scene>


boolean graphnode:isVisible()

Returns true if the node is set to visible, or false otherwise.

graphnode:setColor( col )

Sets the color of the node. Pass a 4-element table with entries { red, green, blue, alpha }. Values are expressed between 0.0 and 1.0.

Example C.108. Use of setColor

<scene>
	<script type="text/x-lua">
		
		myplane = scene:getById("myplane")
		
		--         r    g   b    a
		newcol = { 0.1, 1, 0.5, 0.25 } 
		myplane:setColor(newcol)
		
	</script>
	<object id="myplane" type="primitives://plane.aro"/>
</scene>


graphnode:setVisible( true or false )

Sets the visibility of the node. Invisible nodes are not displayed and do not respond to events e.g. onhover, onclickdown etc.