Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

TypeScript

akimgacem edited this page Jul 4, 2016 · 6 revisions

Getting started with LayaAir TypeScript

TypeScript is a free and open source programming language developed and maintained by Microsoft. Designed for development of large applications and transcompiles to JavaScript. More info at: typescriptlang

Software requirement:

Installation Guide:

  1. Integrated development environment * Visual Studio 2015 :
    • [EMPTY SECTION]
* LayaFlash IDE :
 - [EMPTY SECTION]
  1. Sample code:
  • Hello Laya :
/// <reference path="../../libs/LayaAir.d.ts" />
class Sprite_DisplayImage{

    constructor(){
        Laya.init(550, 400);
        Laya.stage.scaleMode = "showall";

        var ape = new Laya.Sprite();
        //Loading our monkey
        ape.loadImage("res/apes/monkey2.png", 220, 128);

        Laya.stage.addChild(ape);
    }
}
new Sprite_DisplayImage();
  • Display 2D image :
  • Add your asset ressource layabox.png in bin/h5/ folder, you can get some from layaair-examples
  • then write the following code :
/// <reference path="../../libs/LayaAir.d.ts" />
class Sprite_DisplayImage{

    constructor(){
        Laya.init(480, 320);
        Laya.stage.scaleMode = "showall";

        var ape = new Laya.Sprite();
        //Loading our monkey
        ape.loadImage("layabox.png",  0, 0 , 240, 160);

        Laya.stage.addChild(ape);
    }
}
new Sprite_DisplayImage();
  • 3D display :
/// <reference path="../../libs/LayaAir.d.ts" />
class Sprite_DisplayImage{

    constructor(){
        Laya.init(550, 400);
        Laya.stage.scaleMode = "showall";

        var ape = new Laya.Sprite();
        //Loading our monkey
        ape.loadImage("res/apes/monkey2.png", 220, 128);

        Laya.stage.addChild(ape);
    }
}
new Sprite_DisplayImage();

Further more:

Clone this wiki locally