< Zurück

02.12.2012 22:53:00 • Categories: Monkey X, 2D Game SDK / Framework, Multiplatform • Tags: Monkey, FantomEngine

Monkey: fantomEngine - using text object as a button

Strict

rem

   Script:      touchTest.monkey    Description:   Sample Script fantomEngine to display the use of touch events    Author:       Michael

end

Import fantomEngine Global g:game

'*** Class game Extends App    Field eng:engine    Field font1:ftFont    '------------------------------------------    Method CreateObjects:Int()

      'Create a box       Local b:ftObject = eng.CreateBox(100,50,eng.canvasWidth/2,eng.canvasHeight/2-150)       'Set TouchMode to bounding box(2)    ... 1=Circle       b.SetTouchMode(2)       b.SetName("Box")

      'Create a circle       Local c:ftObject = eng.CreateCircle(50,eng.canvasWidth/2,eng.canvasHeight/2)       c.SetTouchMode(1)       c.SetName("Circle")

      'Create a text       Local t:ftObject = eng.CreateText(font1,"This is a clickable text", eng.canvasWidth/2,eng.canvasHeight/2+150,1)       t.SetTouchMode(2)       t.SetName("Text")

      Return 0    End    '------------------------------------------    Method OnCreate:Int()       SetUpdateRate(60)

      'Store the engine instance       eng = New engine

      'Load the font bitmap       font1 = eng.LoadFont("bo_font")             '<========== please change this to a font that you have

      'Create the objects       CreateObjects()       Return 0    End

   '------------------------------------------    Method OnUpdate:Int()       Local d:Float = Float(eng.CalcDeltaTime())/60.0       eng.Update(Float(d))       'check if you have a touch hit and then do a touch check.       If TouchHit(0) Then   eng.TouchCheck()       Return 0    End

   '------------------------------------------    Method OnRender:Int()       Cls       eng.Render()       Return 0    End End  

'*** Class engine Extends ftEngine    '------------------------------------------    Method OnObjectTouch:Int(obj:ftObject, touchId:Int)       Print ("Object "+obj.GetName()+" was hit!")       Return 0    End End

'*** Function Main:Int()    g = New game    Return 0 End


< Zurück | ^ nach oben