We need to write something into those textboxes. What we'll do in this case is call an update
method in HUD
periodically, so that it can refresh the data and print it on the screen:
function HUD:update () local x, y = Character.prop:getScl ()
We get the scale that we used to set the character's direction, and store it in a local variable
x
:if x > 0 then self.leftRightIndicator:setString ( "Left" ) else self.leftRightIndicator:setString ( "Right" ) end
If you remember what we did before, this should be pretty clear. In order to turn right we scaled the character's
prop
to-1
in thex
axis, and to1
to turn the character to the left. So that's what we're doing here. If thex
value of the scale is positive, then we're facing left. Otherwise, if it is-1
, we're facing right. Then, depending on the case, we useMOAITextBox:setString
to update the string with the correct direction.x, y = Character.physics.body:getPosition () self.positionIndicator...