API Docs for: 最后更新日期:2014年8月25日
Google搜索   
Show:

LGlobal Class

Defined in: main/LGlobal.js:1

Available since 1.0.0

Global Class

Methods

divideCoordinate

(
  • width
  • height
  • row
  • col
)
Array public static

Defined in main/LGlobal.js:692

Available since 1.3.1

Split to 2-dimensional arrays from the width and height.

Parameters:

  • width Float

    width

  • height Float

    height

  • row Int

    rows

  • col Int

    cols

Returns:

Array:

2-dimensional arrays

Example:

LInit(50, "legend", 800, 480, main);
function main () {
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("player.png", "bitmapData");
}
function loadBitmapdata(event){
    var backLayer = new LSprite();
    addChild(backLayer);
    var list = LGlobal.divideCoordinate(480,630,3,4);
    var data = new LBitmapData(event.target,0,0,120,210);
    player = new LAnimation(backLayer,data,list);
    backLayer.addEventListener(LEvent.ENTER_FRAME,onframe);
}
function onframe(){
    player.onframe();
}

hitPolygon

(
  • vertices
  • x
  • y
)
Boolean public static

Defined in main/LGlobal.js:744

Available since 1.8.9

HitTest polygon and point

Parameters:

  • vertices Array

    Polygon[[x1,y1],[x2,y2],[x3,y3],......]

  • x Float

    检测点的x坐标

  • y Float

    检测点的y坐标

Returns:

Boolean:

Returns true if hit

Example:

LGlobal.setDebug(true);
var layer = new LSprite();
addChild(layer);
var vertices = [[50,100],[150,50],[100,150]];
layer.graphics.drawVertices(1,"#000000",vertices);
var point1 = [100,100];
layer.graphics.drawArc(1,"#000000",[point1[0],point1[1],2,0,2*Math.PI]);
var point2 = [50,200];
layer.graphics.drawArc(1,"#000000",[point2[0],point2[1],2,0,2*Math.PI]);
trace(LGlobal.hitPolygon(vertices,point1[0],point1[1]));//out:true
trace(LGlobal.hitPolygon(vertices,point2[0],point2[1]));//out:false

hitTestArc

(
  • objA
  • objB
  • objAR
  • objBR
)
Boolean public static

Defined in main/LGlobal.js:885

Available since 1.4.1

HitTest two objects as circles

If the object is rotated, you can not use this method for hitTest, please use the LSprite class's hitTestObject

Parameters:

Returns:

Boolean:

Returns true if hit

Example:

LGlobal.setDebug(true);
var rectLayer1 = new LSprite();
rectLayer1.graphics.drawArc(1,"#000000",[100,100,100,0,2*Math.PI]);
addChild(rectLayer1);
var rectLayer2 = new LSprite();
rectLayer2.alpha = 0.5;
rectLayer2.x = 150;
rectLayer2.graphics.drawArc(1,"#000000",[100,100,100,0,2*Math.PI]);
addChild(rectLayer2);
var rectLayer3 = new LSprite();
rectLayer3.alpha = 0.5;
rectLayer3.x = 300;
rectLayer3.graphics.drawArc(1,"#000000",[100,100,100,0,2*Math.PI]);
addChild(rectLayer3);
//[100,100,100,0,2*Math.PI] vs [100,100,100,0,2*Math.PI]
trace(LGlobal.hitTestArc(rectLayer1,rectLayer2));//out:true
//[115,115,70,0,2*Math.PI] vs [115,115,70,0,2*Math.PI]
trace(LGlobal.hitTestArc(rectLayer2,rectLayer3,70,70));//out:false

hitTestPolygon

(
  • vertices
  • vertices
)
Boolean public static

Defined in main/LGlobal.js:791

Available since 1.9.0

HitTest polygon and circle

Parameters:

  • vertices Array

    PolygonA[[x1,y1],[x2,y2],[x3,y3],......]

  • vertices Array

    PolygonB[[x1,y1],[x2,y2],[x3,y3],......]

Returns:

Boolean:

Returns true if hit

Example:

LGlobal.setDebug(true);
var layer = new LSprite();
addChild(layer);
var vertices = [[50,100],[150,50],[100,150]];
layer.graphics.drawVertices(1,"#000000",vertices);
var vertices1 = [[120,60],[250,150],[100,100]];
layer.graphics.drawVertices(1,"#000000",vertices1);
var vertices2 = [[70,200],[100,160],[200,300]];
layer.graphics.drawVertices(1,"#000000",vertices2);
trace(LGlobal.hitTestPolygon(vertices,vertices1));//out:true
trace(LGlobal.hitTestPolygon(vertices,vertices2));//out:false

hitTestPolygonArc

(
  • vertices
  • circle
)
Boolean public static

Defined in main/LGlobal.js:838

Available since 1.9.0

HitTest polygon and circle

Parameters:

  • vertices Array

    Polygon[[x1,y1],[x2,y2],[x3,y3],......]

  • circle Array

    circle[x,y,radius,radius*radius]

Returns:

Boolean:

Returns true if hit

Example:

LGlobal.setDebug(true);
var layer = new LSprite();
addChild(layer);
var vertices = [[50,100],[150,50],[100,150]];
layer.graphics.drawVertices(1,"#000000",vertices);
var circle1 = [170,100,50,2500];
layer.graphics.drawArc(1,"#000000",[circle1[0],circle1[1],circle1[2],0,2*Math.PI]);
var circle2 = [50,200,50,2500];
layer.graphics.drawArc(1,"#000000",[circle2[0],circle2[1],circle2[2],0,2*Math.PI]);
trace(LGlobal.hitTestPolygonArc(vertices,circle1));//out:true
trace(LGlobal.hitTestPolygonArc(vertices,circle2));//out:false

hitTestRect

(
  • objA
  • objB
  • vecA
  • vecB
)
Boolean public static

Defined in main/LGlobal.js:939

Available since 1.4.1

HitTest two objects as rectangles, Equivalent to hitTest

If the object is rotated, you can not use this method for hitTest, please use the LSprite class's hitTestObject

Parameters:

  • objA LDisplayObject

    LDisplayObject A

  • objB LDisplayObject

    LDisplayObject B

  • vecA Array

    reset the range of LDisplayObject A [width,height]

  • vecB Array

    reset the range of LDisplayObject B [width,height]

Returns:

Boolean:

Returns true if hit

Example:

LGlobal.setDebug(true);
var rectLayer1 = new LSprite();
rectLayer1.graphics.drawRect(1,"#000000",[0,0,200,200],true,"#FF0000");
addChild(rectLayer1);
var rectLayer2 = new LSprite();
rectLayer2.alpha = 0.5;
rectLayer2.x = 150;
rectLayer2.graphics.drawRect(1,"#000000",[0,0,200,200],true,"#00FF00");
addChild(rectLayer2);
var rectLayer3 = new LSprite();
rectLayer3.alpha = 0.5;
rectLayer3.x = 300;
rectLayer3.graphics.drawRect(1,"#000000",[0,0,200,200],true,"#0000FF");
addChild(rectLayer3);
//[0,0,200,200] vs [0,0,200,200]
trace(LGlobal.hitTestRect(rectLayer1,rectLayer2));//out:true
//[30,0,140,200] vs [30,0,140,200]
trace(LGlobal.hitTestRect(rectLayer2,rectLayer3,[140,200],[140,200]));//out:false

resize

(
  • width
  • height
)
public static

Defined in main/LGlobal.js:1034

Available since 1.9.0

change the screen size

Parameters:

  • width Float

    screen width

  • height Float

    screen height

Example:

LInit(1000/60, "legend", 240, 240, main);
function main () {
    LGlobal.resize(400,100);
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("face.jpg", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapdata = new LBitmapData(event.target);  
    var bitmap = new LBitmap(bitmapdata);
    addChild(bitmap);
}

screen

(
  • value
)
public static

Defined in main/LGlobal.js:1138

Available since 1.6.0

Full screen display or to scale the screen size

Parameters:

  • value String | float

    LGlobal.FULL_SCREEN or Screen size scaling value

Example:

LInit(1000/60, "legend", 240, 240, main);
function main () {
    LGlobal.stageScale = LStageScaleMode.SHOW_ALL;
    LGlobal.screen(LStage.FULL_SCREEN);
    //you can also use it like : LGlobal.screen(1.5);
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("face.jpg", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapdata = new LBitmapData(event.target);  
    var bitmap = new LBitmap(bitmapdata);
    addChild(bitmap);
}

setDebug

(
  • value
)
public static

Defined in main/LGlobal.js:269

Available since 1.4.0

Setting the debug mode is on.

*When the game is released, you must set the debug mode off.

Parameters:

  • value Boolean

    the debug mode on or off

Example:

LInit(50, "legend", 800, 480, main);
function main () {
    LGlobal.setDebug(true);
    trace("test01", "test02", "test03");
}    

setFrameRate

(
  • speed
)
public static

Defined in main/LGlobal.js:1000

Available since 1.5.0

game speed reset

Parameters:

  • speed Float

    game speed(milliseconds), FPS = 1000 / speed.

Example:

LGlobal.setFrameRate(1000/60);

Properties

FULL_SCREEN

String public static

Defined in main/LGlobal.js:11

Available since 1.6.0

[static] Defines the value of the full screen.

Please refer LGlobal.screen function

LGlobal.align

String public static

Defined in main/LGlobal.js:130

Available since 1.8.6

A value from the StageAlign class that specifies the alignment of the stage in the browser.

Example:

LInit(50, "legend", 240, 240, main);
function main () {
    LGlobal.align = LStageAlign.BOTTOM_MIDDLE;
    LGlobal.stageScale = LStageScaleMode.SHOW_ALL;
    LSystem.screen(LStage.FULL_SCREEN);
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("face.jpg", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapdata = new LBitmapData(event.target);  
    var bitmap = new LBitmap(bitmapdata);
    addChild(bitmap);
}

LGlobal.android

Boolean public static

Defined in main/LGlobal.js:192

Available since 1.0.0

Whether the Android browser.

LGlobal.aspectRatio

String public static

Defined in main/LGlobal.js:23

Available since 1.8.1

Sets the stage to an orientation with the specified aspect ratio.

LANDSCAPE、PORTRAIT

LGlobal.backgroundColor

String public static

Defined in main/LGlobal.js:202

Available since 1.7.7

The background color of the game screen.

LGlobal.canTouch

Boolean public static

Defined in main/LGlobal.js:164

Available since 1.0.0

Equivalent to LGlobal.mobile.

LGlobal.canvas

CanvasRenderingContext2D public static

Defined in main/LGlobal.js:42

Available since 1.0.0

context object.

LGlobal.canvasObj

HTML elements public static

Defined in main/LGlobal.js:33

Available since 1.8.1

canvas Tag.

LGlobal.destroy

Boolean public static

Defined in main/LGlobal.js:211

Available since 1.7.7

When a LDisplayObject object be removed. Whether the object to empty.

Default: true

LGlobal.height

Int public static

Defined in main/LGlobal.js:81

Available since 1.0.0

game screen's height(canvas's height)

LGlobal.ios

Boolean public static

Defined in main/LGlobal.js:183

Available since 1.0.0

Whether the IOS browser.

LGlobal.keepClear

Boolean public static

Defined in main/LGlobal.js:224

Available since 1.8.7

Whether clear canvas in each frame.

If the game is not a transparent background, you can set the value to false.

Default: true

LGlobal.mobile

Boolean public static

Defined in main/LGlobal.js:155

Available since 1.9.0

Whether the current browser is a mobile browser. Equivalent to LGlobal.canTouch.

LGlobal.os

String public static

Defined in main/LGlobal.js:173

Available since 1.0.0

Browser environment. one of the following constants.

OS_IPHONE,OS_IPOD,OS_IPAD,OS_ANDROID,OS_PC。

LGlobal.preventDefault

Boolean public static

Defined in main/LGlobal.js:93

Available since 1.3.1

Mobile web page, Sets scroll gestures to disabled., default true. (scroll disabled)

LGlobal.stage

LSprite public static

Defined in main/LGlobal.js:62

Available since 1.3.1

A LSprite object, the root of all DisplayObjects.

Unless do some extensions, Otherwise, it is not recommended to directly manipulate

LGlobal.stageScale

String public static

Defined in main/LGlobal.js:105

Available since 1.4.0

A value from the LStageScaleMode class that specifies which scale mode to use. The following are valid values:

Example:

LInit(50, "legend", 240, 240, main);
function main () {
    LGlobal.align = LStageAlign.BOTTOM_MIDDLE;
    LGlobal.stageScale = LStageScaleMode.SHOW_ALL;
    LSystem.screen(LStage.FULL_SCREEN);
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("face.jpg", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapdata = new LBitmapData(event.target);  
    var bitmap = new LBitmap(bitmapdata);
    addChild(bitmap);
}

LGlobal.webAudio

Boolean public static

Defined in main/LGlobal.js:51

Available since 1.0.0

If the device supports Web Audio Api, whether to use the Web Audio Api to play audio.

Default: true

LGlobal.width

Int public static

Defined in main/LGlobal.js:72

Available since 1.0.0

game screen's width(canvas's width)