Play the games, create the levels

BonusLevel docs, API presentation

Principles

3 methods to implement (called by the API), 1 for the game engine and 2 for the level editor (minimal implementation).

1 method to call from the game engine (minimal implementation).

Technical constraints

Here is the list of constraints you must follow in your game and in your editor, to make them work with the BL interface. Those constraints are mainly those you have when you deal with a .swf embedded in another .swf.

All Flash versions

  • Frame rate should be set to 30 fps, as that will be the frame rate of the common UI that loads the external game swf files.
  • The background color of the common UI will be white (#FFFFFF). Therefore you will need to include a rectangle filled with the color you wish to appear as the background, and of the same size of your stage, on your main timeline.
  • The game must be resizable but all size are supported. Optimal size of the game and editor is 500x(440 or less) or (500 or less)x440.
  • Preloading your game will be handled for you, therefore you do not need to include a preloader with your game.
  • If your game is using the mouse, you have to call the BL API function cursorOverBLGUI() to check if the mouse cursor is over the BL graphic interface (BL menus, information popups, etc...). When the user is clicking on the mouse button while the cursor is over a BL graphic interface, that shoud not trigger an action in your own swf.
  • Prefer Bitmap to MovieClip, especially for a tilebase game.
  • For the performances, try to avoid using MovieClip as much as possible. Use as many BitmapData as possible. Note that it doesn't mean you have to design your game with bitmap images, as you can pre-render a MovieClip into a Bitmap. Then you can display this Bitmap on the stage instead of the MovieClip.

Actionscript 2 (Flash 8 and below)

  • Sounds. When instantiating new Sound objects you must pass a reference to the movieclip that's doing the instantiation, such as:
    var mysound = new Sound(this);
    If you leave out "this" your game will have no sound when loaded.
  • Some issues with hitTest... If the size of your swf is not 500x(440 or less), you might have troubles with the hitTest function. This is the turn around (thanks to bit-101):
    MovieClip.prototype.oldHitTest = MovieClip.prototype.hitTest;
    MovieClip.prototype.hitTest = function(x, y, sf){
      var obj = {x:x, y:y};
      this._parent.localToGlobal(obj);
      return this.oldHitTest(obj.x, obj.y, sf);
    }
  • You may not use references to _level anywhere in your code. (If you do not know what this means, you probably don't have anything to worry about.)

Actionscript 3 (Flash 9 and over)

  • Most of the AS2 constraints (above) might have been solved in AS3.
  • When you have to display hundreds of display objects on the stage, for performance matters you should prefer using Bitmaps instead of MovieClips.
  • Still for performance and memory matters, when you don't need several frames, use Sprites instead of MovieClips. MoveiClips are heavy and slow.
  • Before accessing the stage property of your swf, you will have to wait for the Event.ADDED_TO_STAGE event. Otherwise stage is null.
  • More generally speaking, becareful when using the stage property in your swf. Be aware for example the stage's size is not the size of your swf when it is embedded. The mouse cursor can be outside your swf while being inside the stage (the MOUSE_LEAVE event will not be triggered in this case).