Events and Delegates

Event handlers are functions that are called when an associated event occurs. Event handler functions must have the same signature as the event. The Mouse & Keyboard tutorial shows how to process events in your programs.

Delegates are a reference type based on the class System.Delegate. Delegates can reference both static functions (that can be called without a specific instance of a class) and instance functions. Delegates forward calls to the appropriate event handlers, thus allowing you to dynamically associate event handlers with events at runtime.

Delegates can be created using the toDelegate function. To register a delegate as an event handler use the AddHandler function. To remove an event handler, use the RemoveHandler function.

var:RenderEventHandler hRender = new RenderEventHandler(toDelegate(csOnRender))
AddHandler(OnRender , hRender)
RemoveHandler(OnRender , hRender)

function csOnRender(){
    var:uint16 indices[] = [ 0, 2, 3, 2, 1, 3, 1, 0, 3, 2, 0, 1 ]
    var:gb.video.VideoDriver driver = base.SceneManager.VideoDriver;
    driver.SetMaterial(material);
    driver.SetTransform(gb.video.TransformationState.World, AbsoluteTransformation);
    driver.DrawVertexPrimitiveList(vertices, indices);
}