Sunday, September 20, 2015

Monkey-X - Beginners - KeyHit(const) - example

KeyHit is different then KeyDown. Look at this example to understand it.

Import mojo

Global lastpressed:Int=10

Class MyGame Extends App

    Method OnCreate()
    End Method
    Method OnUpdate()
        If KeyHit(KEY_SPACE)
            lastpressed = 0
        End If     
    End Method
    Method OnRender()
        If lastpressed < 10 Then
            Cls 200,200,200
            Cls 0,0,0 
        End If        
        SetColor 255,255,255
        DrawText "Monkey-X - KeyHit(key) Example.",10,10
        DrawText "Press the space bar....",10,30
        DrawText "Space last pressed "+lastpressed/60+" second(s) ago",100,100
        DrawText "KeyHit(KEY_SPACE)",100,130
    End Method
End Class

Function Main()
    New MyGame()
End Function

No comments:

Post a Comment