Monkey Documentation

Class App

This is the main application class. More...


Methods:

Detailed Discussion

This is the main application class.

All mojo based applications must declare a class that extends App and that implements the OnCreate, OnUpdate, OnRender and OnLoading methods.

A new instance of this class must be then created inside your applications Main function. The OnCreate, OnUpdate, OnRender and OnLoading methods will be called as necessary while your application runs.

OnCreate is called when mojo has been initialized and your app can safely start using mojo functions. This is generally where code to load resources such and images and sounds goes. This is where the application's update rate is initially set too - see: SetUpdateRate.

OnUpdate is called when the update timer ticks, and is where your game logic code should go. The update timer is set using the SetUpdateRate function.

OnRender is called when your application should render itself. If the update timer is ticking, this is also called as soon as possible after OnUpdate, however OnRender may be called at any time in generally if your application requires refreshing.

OnLoading is called insetad of OnRender when your application should render itself, but there are still resources being loaded.

Import note:

No mojo functions or methods should be used before OnCreate is called! Before this, mojo is not fully initialized and cannot be safely used. This means that global variables cannot be initialied using Millisecs, LoadImage or indeed ANY mojo functions.


Method Documentation

Method OnBack : Int ()

This method is called when the application's 'back' button is pressed.

This method is only used by the android and windows phone 8 targets.

By default, the OnBack method calls OnClose. To override this behavior, you must provide your own OnBack method when extending the App class.

Important! On Windows Phone 8, The only time you can end an application is when the OS calls your app's OnClose or OnBack method. To end an application, use EndApp.

Method OnClose : Int ()

This method is called when the application's 'close' button is pressed.

This method is only used by the glfw, android and windows 8 targets.

By default, the OnClose method calls EndApp. To override this behavior, you must provide your own OnClose method when extending the App class.

Important! On Windows Phone 8, The only time you can end an application is when the OS calls your app's OnClose or OnBack method. To end an application, use EndApp.

Method OnCreate : Int ()

The OnCreate method is called when mojo has been initialized and the application has been successfully created.

At this point, applications can start loading resources such as images and sounds, and set the update rate using SetUpdateRate.

The return value of this method is currently ignored, but should be 0 for future compatibility.

Method OnLoading : Int ()

This method is called instead of OnRender when the application should render itself, but there are still resources such as images or sounds in the process of being loaded.

The return value of this method is currently ignored, but should be 0 for future compatibility.

See also OnRender

Method OnRender : Int ()

This method is automatically called when the application should render itself, such as when the application first starts, or following an OnUpdate call.

If your application is taking to long to update and/render itself, OnRender calls may be skipped to allow it to 'catch up'.

The return value of this method is currently ignored, but should be 0 for future compatibility.

See also OnUpdate, OnLoading

Method OnResize : Int ()

This method is called when the application's device window size changes.

This can occur on the desktop target when a window is resized, or on portable targets when the device is rotated.

To determine the new window size, use the DeviceWidth and DeviceHeight functions.

Method OnResume : Int ()

OnResume is called when your application is made active again after having been in a suspended state.

The return value of this method is currently ignored, but should be 0 for future compatibility.

See also OnSuspend

Method OnSuspend : Int ()

OnSuspend is called when your application is about to be suspended.

While suspended, Mojo will make no further calls to any applications 'On' methods, except for OnResume.

Note that on some targets such as iOS and Android, OnSuspend represents a 'last chance' to save application data before your application is terminated.

The return value from this method is currently ignored, but should be 0 for future compatibility.

See also OnResume

Method OnUpdate : Int ()

This method is automatically called when the application's update timer ticks. Once OnUpdate has been called, mojo will then attempt to call OnRender as soon as possible.

Note that OnUpdate is only called if SetUpdateRate has been called to start the update timer. Otherwise, your application will receive OnRender calls only.

OnUpdate is commonly used in conjunction with OnRender to manage the main game loop. OnUpdate is typically used to update objects and game state, while OnRender is used to draw graphics.

The return value from this method is currently ignored, but should be 0 for future compatibility.

See also SetUpdateRate