Win an Ipad
  Developer   Documents   Game

Game

New document short description

Moscrif Framework includes two different libraries regarding game 2D development. If you require to use physics in your you might use Box2D library. If physics are not required, you may use game2D library.

Game project starts with Game instance. What the game should do at the start is defined within onStart method. Game instance also handle all input events came from the user on the device screen..

include "lib://core/log.ms";
include "lib://game2d/game.ms" //create new game instance
var game = new Game(); //run game
game.run();

The most significant events of the game instance are listed in the table below:

Event name Description
onDraw Event fired when game is ready be drawn
onProcess Event fired when system idle allows to process the game
onStart Event fired when game is started
onPointerPressed Event fired when game is started
onPointerDragged Event fired when game is started
onPointerReleased Event fired when screen pointer is released

 

Game instance is managing game scenes. Game.push method adds a game scene into Game instance and it displays the game scene on the device screen. Method Game.pop sets previous scene as the current scene and displays it on the device screen.

include "app://gui/menuScene.ms";
include "app://gui/snakeButton.ms";
//prepare game instance before it runs
game.onStart = function(sender)
{
    this.terminate = false;
    this.game = null;     //Create menu scene
    this.menu = new MenuScene();
    this.push(this.menu); }

Game instance allows to use game Sprites, as well. To add a game sprite, use Game.add method. See example below where background is a instance of the Sprite with its own draw method added to Game instance.

game.onStart = function(sender)
{
    //load background
    this.bg = new Sprite({image : Bitmap.fromFile("app://gfx/bg.png")});
    this.bg.draw = function(canvas)
    {
         //draw background
         canvas.drawBitmap(this.image, 0, 0);
    }
    this.add(this.bg)
}

 PhysicsContact   Game   Scene 
Write a Comment (0)
Subject
Please complete this mandatory field.
HTML Tags Not Allowed!
Comment
Please complete this mandatory field.