mooball
    Preparing search index...

    Interface Callback

    interface Callback {
        add(name: string, metadata: any): void;
        remove(name: string): void;
    }
    Index

    Methods

    Methods

    • Creates all custom callbacks about a new event called eventName. For example, this function might have to be used (and maybe overridden for usage of metadata) in a GUI application to define event callbacks related to gui events such as keyboard, mouse, touch, timer etc. The main event callback defined in all Room objects to trigger the new callbacks is "_on" + eventName.

      Parameters

      • name: string

        The name of the new event, which should start with a capital letter.

      • metadata: any

        This value is currently not used anywhere; but just in case, the default keys for this object is as follows:

        • params: string[]: Short explanations for each parameter of this event.

      Returns void

      void.

      Let's say that we are working in browser environment and we need our plugins to react to mouse wheel events on a HTMLElement. Here are the steps to make this happen:

      • Just after initializing the API, add this line:

        Callback.add("Wheel")
        

        This will define the main _onWheel() callback in every Room object that is created after this line is executed.

      • When the wheel event happens, call the _onWheel() callback.

        document.getElementById("canvas").onwheel = function(event){
        room._onWheel(event);
        };

        It will trigger all RoomConfig, Plugin and Renderer callbacks for all Room objects.

      • Now we might define and use the callbacks wherever we want. Note that the structure of these functions will always be the same for every callback created by Callback.add.

        • Inside a RoomConfig: (We do not need to add all 3 callbacks.)

          this.onBeforeWheel = function(event){
          //return customData;
          };
          this.onWheel = function(event, customData){
          //...
          };
          this.onAfterWheel = function(event, customData){
          //...
          };
        • Inside a Plugin or a Renderer:

          this.onWheel = function(event, customData){
          //...
          };
        • By directly modifying the built-in RoomConfig inside a Room object: (We do not need to add all 3 callbacks.)

          room.onBeforeWheel = function(event){
          //return customData;
          };
          room.onWheel = function(event, customData){
          //...
          };
          room.onAfterWheel = function(event, customData){
          //...
          };
    • Removes the callbacks created by Callback.add. Added for convenience. This function should not normally be needed.

      Parameters

      • name: string

        The name of the event to be removed.

      Returns void

      void.