LGlobal Class
Global Class
Item Index
Methods
- divideCoordinate static
- hitPolygon static
- hitTestArc static
- hitTestPolygon static
- hitTestPolygonArc static
- hitTestRect static
- resize static
- screen static
- setDebug static
- setFrameRate static
Properties
- FULL_SCREEN static
- LGlobal.align static
- LGlobal.android static
- LGlobal.aspectRatio static
- LGlobal.backgroundColor static
- LGlobal.canTouch static
- LGlobal.canvas static
- LGlobal.canvasObj static
- LGlobal.destroy static
- LGlobal.height static
- LGlobal.ios static
- LGlobal.keepClear static
- LGlobal.mobile static
- LGlobal.os static
- LGlobal.preventDefault static
- LGlobal.stage static
- LGlobal.stageScale static
- LGlobal.webAudio static
- LGlobal.width static
Methods
divideCoordinate
-
width
-
height
-
row
-
col
Split to 2-dimensional arrays from the width and height.
Parameters:
-
width
Floatwidth
-
height
Floatheight
-
row
Introws
-
col
Intcols
Returns:
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
HitTest polygon and point
Parameters:
-
vertices
ArrayPolygon[[x1,y1],[x2,y2],[x3,y3],......]
-
x
Float检测点的x坐标
-
y
Float检测点的y坐标
Returns:
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
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:
-
objA
LDisplayObjectLDisplayObject A
-
objB
LDisplayObjectLDisplayObject B
-
objAR
Floata new Radius
-
objBR
Floata new Radius
Returns:
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
HitTest polygon and circle
Parameters:
-
vertices
ArrayPolygonA[[x1,y1],[x2,y2],[x3,y3],......]
-
vertices
ArrayPolygonB[[x1,y1],[x2,y2],[x3,y3],......]
Returns:
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
HitTest polygon and circle
Parameters:
-
vertices
ArrayPolygon[[x1,y1],[x2,y2],[x3,y3],......]
-
circle
Arraycircle[x,y,radius,radius*radius]
Returns:
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
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
LDisplayObjectLDisplayObject A
-
objB
LDisplayObjectLDisplayObject B
-
vecA
Arrayreset the range of LDisplayObject A [width,height]
-
vecB
Arrayreset the range of LDisplayObject B [width,height]
Returns:
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
change the screen size
Parameters:
-
width
Floatscreen width
-
height
Floatscreen 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
Full screen display or to scale the screen size
Parameters:
-
value
String | floatLGlobal.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
Setting the debug mode is on.
*When the game is released, you must set the debug mode off.
Parameters:
-
value
Booleanthe debug mode on or off
Example:
LInit(50, "legend", 800, 480, main);
function main () {
LGlobal.setDebug(true);
trace("test01", "test02", "test03");
}
setFrameRate
-
speed
game speed reset
Parameters:
-
speed
Floatgame speed(milliseconds), FPS = 1000 / speed.
Example:
LGlobal.setFrameRate(1000/60);
Properties
FULL_SCREEN
String
public
static
[static] Defines the value of the full screen.
Please refer LGlobal.screen function
LGlobal.align
String
public
static
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
Whether the Android browser.
LGlobal.aspectRatio
String
public
static
Sets the stage to an orientation with the specified aspect ratio.
LANDSCAPE、PORTRAIT
LGlobal.backgroundColor
String
public
static
The background color of the game screen.
LGlobal.canTouch
Boolean
public
static
Equivalent to LGlobal.mobile.
LGlobal.canvas
CanvasRenderingContext2D
public
static
context object.
LGlobal.canvasObj
HTML elements
public
static
canvas Tag.
LGlobal.destroy
Boolean
public
static
When a LDisplayObject object be removed. Whether the object to empty.
Default: true
LGlobal.height
Int
public
static
game screen's height(canvas's height)
LGlobal.ios
Boolean
public
static
Whether the IOS browser.
LGlobal.keepClear
Boolean
public
static
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
Whether the current browser is a mobile browser. Equivalent to LGlobal.canTouch.
LGlobal.os
String
public
static
Browser environment. one of the following constants.
OS_IPHONE,OS_IPOD,OS_IPAD,OS_ANDROID,OS_PC。
LGlobal.preventDefault
Boolean
public
static
Mobile web page, Sets scroll gestures to disabled., default true. (scroll disabled)
LGlobal.stage
LSprite
public
static
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
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
If the device supports Web Audio Api, whether to use the Web Audio Api to play audio.
Default: true
LGlobal.width
Int
public
static
game screen's width(canvas's width)