Static

Description

Initialize CanvasEngine by setting the canvas. Note two ways to declare a canvas in HTML :

  1. <canvas id="canvas_id" width="640" height="480"></canvas>
    
  2. <div id="canvas_id" width="640" height="480"></div>
    

In case you use the div tag to add a layer of DOM elements is possible. For example, to add forms.

In ready method, you can use jQuery (Do not forget to include the library in the header before) :

    var el = $('<div>');
    stage.append(el);

Valid for version >= 1.3.1

Usage

Parameters

  • canvas {String}

    canvas ID

  • params {Object} optional

    (optional) additional parameters

    • swf_sound : see Sound class (obsolete, use soundmanager object)
    • soundmanager : (>= 1.2.7) SoundManager options http://www.schillmania.com/projects/soundmanager2/doc/#sm-config

      Example :

      {url: "swf/", debugMode: false}
      
    • cocoonjs : Object indicating the size of the canvas. Use this property if you want to compile your project with CocoonJS (http://ludei.com)

      Example :

      {width: 640, height: 480}
      
    • render : Do not rendering (true by default)

    • contextmenu (>= 1.2.6) : Show right-click menu (false by default)
    • ignoreLoadError (>= 1.2.7) : Begins the scene even if the materials are not loaded

      Example :

      var canvas = CE.defines("canvas_id", {
          ignoreLoadError: true
      }).
       ready(function() {
           canvas.Scene.call("MyScene");
       });
      
      canvas.Scene.New({
          name: "MyScene",
          materials: {
              images: {
                  foo: "path/picture.png"         // picture.png does not exist but ...
              }
          },
          ready: function(stage) {                // ready() is still called
              var el = this.createElement();
              el.drawImage("foo");                // image is ignored
              stage.append(el);
          }
      });
      

Example

"CE" is equivalent to "CanvasEngine"

var canvas = CE.defines("canvas_id").
             ready(function() {
                // DOM is ready
             });

View ready method

Discussion