Strict #rem Script: BitmapFont.cxs Description: Sample script that shows how load bitmap fonts and draw multi-line text Author: Michael Hartlef #End ' Import the mojo2 framework Import mojo2 '******************************************************************* ' Define myClass, which extends (ie inherits) the Cerberus X App class. Class myClass Extends App 'Create some class fields Field canvasWidth:Int ' A field to store the width of the canvas. Field canvasHeight:Int ' Holds the height of the canvas. Field myCanvas:Canvas ' Stores the canvas to draw on. Field myFont:Font ' A field to hold the loaded font. '--------------------------------------------------------------- ' The OnCreate Method inside the App class is always called at the start of your app. ' It is a perfect place to load resources into your app. Method OnCreate:Int() ' By setting the update rate to 0, there will be always an OnRender call after OnUpdate, no matter how long it takes. ' It will also run as fast as your sync rate of your hardware runs. SetUpdateRate(60) myCanvas = New Canvas() ' Determine the width of the device canvas. canvasWidth = DeviceWidth() ' Determine the height of the device canvas. canvasHeight = DeviceHeight() ' Load and set the bitmap font specified in font.txt. myFont = Font.Load("font.txt") myCanvas.SetFont(myFont) Return(0) End '--------------------------------------------------------------- ' The OnUpdate Method is called at the beginning of a new frame. ' The interval at which it is called depends on SetUpdateRate(); the default is 60 times per second. ' The mojo framework tries to call OnUpdate at the specified rate and if necessary will skip calls to OnRender to reach the goal. Method OnUpdate:Int() Return(0) End '--------------------------------------------------------------- ' The OnRender method will be called after the OnUpdate method. ' It is the place to draw your images or other visual elements. Method OnRender:Int() ' Clear the canvas to black. myCanvas.Clear (0, 0, 0) ' Draw a cross hair. myCanvas.DrawLine(0, canvasHeight/2, canvasWidth, canvasHeight/2) myCanvas.DrawLine(canvasWidth/2, 0, canvasWidth/2, canvasHeight) ' Now draw some text over several lines, splitting it into a string array using the "~n" (new line) separator. myCanvas.DrawText( String("Hello World~nCerberus X is AWESOME!").Split("~n"), canvasWidth/2, canvasHeight/2, 0.5, 0.5) ' Flush the canvas so it becomes visible. myCanvas.Flush Return(0) End End '--------------------------------------------------------------- ' The Main function is the starting point of every Cerberus X app. Function Main:Int() ' Create an instance of the class that you have defined above. New myClass() Return(0) End