1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
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 |