Win an Ipad
  Developer   Documents   Scene

Scene

Scene defines character of the game scene. Scene registers gamelayer, game sprites and game controls. Method Scene.add adds a gameobject to the scene.


Each time system idle allows to process the game, current game scene is processed together with the game objects within it. This rule is valid for drawing feature. Once the game is ready to be drawn, current scene and all the game objects within the scene are drawn.


There are special events - Scene.onEnter and Scene.onExit. These events define what is the scene supposed to do on the enter and on the exit.

Example below shows how to define the menu scene containing game controls.


include "app://core/constants.ms";
include "lib://game2d/scene.ms"; class MenuScene : Scene
{
    function init()
    {
        super.init();
        this._background = Bitmap.fromFile(M_MENU);         this.bContinue = new SnakeButton({image:M_CONTINUE, pressedImage:M_CONTINUE_P});
        this.bContinue.visible = false;
        this.bContinue.x = (this.width - this.bContinue.width)/2;
        this.bContinue.y = this.height / 2;
        this.bContinue.onClick = function() { app.pop(); };
        this.add(this.bContinue);
   
        var bNewGameGyro = new SnakeButton({image:M_NEW_GAME_GYRO, pressedImage:M_NEW_GAME_GYRO_P});
        bNewGameGyro.x = (this.width - bNewGameGyro.width)/2;
        bNewGameGyro.y = this.bContinue.y + this.bContinue.height + M_VERTICAL_SPACE;
        this.add(bNewGameGyro);         var bNewGameTouch = new SnakeButton({image:M_NEW_GAME_TOUCH, pressedImage:M_NEW_GAME_TOUCH_P});
        bNewGameTouch.x = (this.width - bNewGameTouch.width)/2;
        bNewGameTouch.y = bNewGameGyro.y + bNewGameGyro.height + M_VERTICAL_SPACE;
        bNewGameTouch.onClick = function()
        {
            app.gameScene = new GameScene();
            app.push(app.gameScene);
            this super.bContinue.visible = true;
        }
        this.add(bNewGameTouch);         var bQuit = new SnakeButton({image:M_QUIT, pressedImage:M_QUIT_P});
        bQuit.x = (this.width - bQuit.width)/2;
        bQuit.y = bNewGameTouch.y + bNewGameTouch.height + M_VERTICAL_SPACE;
        bQuit.onClick = :: app.quit();
        this.add(bQuit);
    }     property width(v)
    {
        get return this._background.width;
    }     property height(v)
    {
        get return this._background.height;
    }     function showContinueBttn()
    {
        this.bContinue.visible = true;
    }     function draw(canvas)
    {
        canvas.drawBitmap(this._background, 0, 0);
        super.draw(canvas);
    }
}

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