Thursday, March 12, 2015

Monkey-X - Beginners - String position and FromChar - code example


Here code that shows how to print a single character from a string.

Code below :

Import mojo

Global sp:Int=0
Global str:String="Hello World."

Class MyGame Extends App

    Method OnCreate()
        SetUpdateRate(5)
    End Method
    Method OnUpdate()        
        sp+=1
        If sp>=str.Length Then sp=0
    End Method
    Method OnRender()
        Cls 0,0,0 
        SetColor 255,255,255
        PushMatrix()
        Scale 2.0,2.0
        DrawText "String Character example.",0,0
        DrawText String.FromChar(str[sp]),0,15
        DrawText "Character "+sp+ " of : "+str,0,30
        PopMatrix()
    End Method
End Class


Function Main()
    New MyGame()
End Function

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.