API Docs for: 1.10.1 最后更新日期:2016年03月28日
Google搜索   
Show:

UI:LComboBox Class

Extends LSprite

Available since 0.1.0

lufylegend.js专用UI,组合框。

使用时需要引进lufylegend.ui-x.x.x.js文件。

Constructor

UI:LComboBox

(
  • size
  • color
  • font
  • layer
  • layerUp
  • layerOver
)
public

Defined in lib/ui/LComboBox-0.1.2.js:1

Available since 0.1.0

Parameters:

  • size Int

    [可选]组合框文字的大小。

  • color String

    [可选]组合框文字的颜色。

  • font String

    [可选]组合框文字的格式。

  • layer LPanel

    [可选]组合框的背景样式。

  • layerUp LDisplayObject

    [可选]组合框的按钮抬起状态样式。

  • layerOver LDisplayObject

    [可选]组合框的按钮抬起状态样式。

Methods

addBodyCircle

(
  • radius
  • cx
  • cy
  • type
  • density
  • friction
  • restitution
)
B2Body public

Inherited from LSprite: display/LSprite.js:791

Available since 1.4.0

LBox2d相关。

设定圆形body。

Parameters:

  • radius Float

    半径

  • cx Float

    圆心坐标x

  • cy Float

    圆心坐标y

  • type Int

    是否动态(1或0)

  • density Float

    密度

  • friction Float

    摩擦

  • restitution Float

    弹性

Returns:

B2Body:

返回一个被创建的box2d的body

addBodyPolygon

(
  • width
  • height
  • type
  • density
  • friction
  • restitution
)
B2Body public

Inherited from LSprite: display/LSprite.js:806

Available since 1.4.0

LBox2d相关。

设定矩形body。

Parameters:

  • width Float

    矩形宽

  • height Float

    矩形高

  • type Int

    是否动态(1或0)

  • density Float

    密度

  • friction Float

    摩擦

  • restitution Float

    弹性

Returns:

B2Body:

返回一个被创建的box2d的body

addBodyVertices

(
  • vertices
  • cx
  • cy
  • type
  • density
  • friction
  • restitution
)
B2Body public

Inherited from LSprite: display/LSprite.js:820

Available since 1.4.0

LBox2d相关。

以定点数组形式设定任意形状的body。

Parameters:

  • vertices Float

    顶点数组

  • cx Float

    中心坐标x

  • cy Float

    中心坐标y

  • type Int

    是否动态(1或0)

  • density Float

    密度

  • friction Float

    摩擦

  • restitution Float

    弹性

Returns:

B2Body:

返回一个被创建的box2d的body

addChild

(
  • child
)
LDisplayObject public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:77

Available since 1.0.0

将一个 DisplayObject 子实例添加到该 LDisplayObjectContainer 实例中。子项将被添加到该 LDisplayObjectContainer 实例中其他所有子项的前(上)面。(要将某子项添加到特定索引位置,请使用 addChildAt() 方法。)

如果添加一个已将其它显示对象容器作为父项的子对象,则会从其它显示对象容器的子列表中删除该对象。

Parameters:

  • child LDisplayObject

    要作为该 LDisplayObjectContainer 实例的子项添加的 LDisplayObject 实例。

Returns:

LDisplayObject:

在 child 参数中传递的 LDisplayObject 实例。

Example:

var bitmapdata = new LBitmapData("#FF0000",0,0,100,100);  
var bitmap = new LBitmap(bitmapdata);
var layer = new LSprite();
addChild(layer);
layer.addChild(bitmap);

addChildAt

(
  • child
  • index
)
LDisplayObject public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:107

Available since 1.8.0

将一个 LDisplayObject 子实例添加到该 LDisplayObjectContainer 实例中。该子项将被添加到指定的索引位置。索引为 0 表示该 LDisplayObjectContainer 对象的显示列表的后(底)部。

例如,下例在索引位置 0、2、1 处分别显示 a、b、c 三个显示对象:

如果添加一个已将其它显示对象容器作为父项的子对象,则会从其它显示对象容器的子列表中删除该对象。

Parameters:

  • child LDisplayObject

    要作为该 LDisplayObjectContainer 实例的子项添加的 LDisplayObject 实例。

  • index Int

    添加该子项的索引位置。 如果指定当前占用的索引位置,则该位置以及所有更高位置上的子对象会在子级列表中上移一个位置。

Returns:

LDisplayObject:

在 child 参数中传递的 LDisplayObject 实例。

Example:

var container = new LSprite();
var circle1 = new LSprite();
var circle2 = new LSprite();
container.addChild(circle1);
container.addChildAt(circle2, 0);
trace(container.getChildAt(0) == circle2); // true
trace(container.getChildAt(1) == circle1); // true

addEventListener

(
  • type
  • listener
)
public

Inherited from LEventDispatcher: events/LEventDispatcher.js:16

Available since 1.8.0

使用 LEventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。可以为特定类型的事件、阶段和优先级在显示列表中的所有节点上注册事件侦听器。

成功注册一个事件侦听器后,无法通过额外调用 addEventListener() 来更改其优先级。要更改侦听器的优先级,必须首先调用 removeListener()。然后,可以使用新的优先级再次注册该侦听器。

如果不再需要某个事件侦听器,可调用 removeEventListener() 删除它,否则会产生内存问题。

Parameters:

  • type String

    事件的类型。

  • listener Function

    处理事件的侦听器函数。

addShape

(
  • type
  • arg
)
Array public

Inherited from LSprite: display/LSprite.js:604

Available since 1.9.0

添加碰撞形状,指定碰撞的范围。如果没有添加碰撞形状,则会默认使用最大矩形范围来碰撞检测。

添加矩形 : addShape(LShape.RECT,[20,140,200,100])

添加圆形 : addShape(LShape.ARC,[110,80,60])

添加多边形 : addShape(LShape.VERTICES,[[10,10],[50,100],[100,70]])

Parameters:

  • type String

    形状的类型.

  • arg Array

    形状参数.

Returns:

Array:

被添加的形状组.

Example:

LInit(20,"legend",800,450,main);
function main () {
    LGlobal.setDebug(true);
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("face.jpg", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapData = new LBitmapData(event.currentTarget);//width:240,height:240
    var bitmap01 = new LBitmap(bitmapData);
    var layer01 = new LSprite();
    addChild(layer01);
    layer01.addChild(bitmap01);
    var rect1 = new LSprite();
    rect1.x = 180;
    rect1.graphics.drawRect(2,"#FF0000",[0,0,100,100]);
    addChild(rect1);
    var bitmap02 = new LBitmap(bitmapData);
    var layer02 = new LSprite();
    layer02.x = 300;
    addChild(layer02);
    layer02.addChild(bitmap02);
    layer02.addShape(LShape.ARC,[110,80,60]);
    layer02.addShape(LShape.RECT,[20,140,200,100]);
    var rect2 = new LSprite();
    rect2.x = 480;
    rect2.graphics.drawRect(2,"#FF0000",[0,0,100,100]);
    addChild(rect2);
    var rect3 = new LSprite();
    rect3.x = 480;
    rect3.y = 120;
    rect3.graphics.drawRect(2,"#FF0000",[0,0,100,100]);
    addChild(rect3);
    trace(layer01.hitTestObject(rect1));//true
    trace(layer02.hitTestObject(rect2));//false
    trace(layer02.hitTestObject(rect3));//true
}

addShapes

(
  • shapes
)
public

Inherited from LSprite: display/LSprite.js:663

Available since 1.9.8

添加碰撞形状组,指定碰撞的范围。

Parameters:

  • shapes Array

    形状组.

    例如 : [{"type" : LShape.RECT, "arg" : [20,140,200,100]},{"type" : LShape.ARC, "arg" : [110,80,60]},{"type" : LShape.VERTICES, "arg" : [[10,10],[50,100],[100,70]]}]

cacheAsBitmap

(
  • value
)
public

Inherited from LDisplayObject: display/LDisplayObject.js:407

Available since 1.9.11

如果设置为 true,则运行时将缓存显示对象的内部位图表示形式。此缓存可以提高包含复杂矢量内容的显示对象的性能。速度可能会大大加快,具体取决于矢量内容的复杂性。

*动态改变的对象无法使用cacheAsBitmap

Parameters:

  • value Bool

    分配给触摸点的整数(触摸设备)。

Example:

var layer = new LSprite();
layer.x = layer.y = 100;
addChild(layer);
var bitmapdata = new LBitmapData(event.target);
var bitmap = new LBitmap(bitmapdata);
layer.addChild(bitmap);
bitmap = new LBitmap(bitmapdata);
bitmap.x = bitmap.y = 50;
layer.addChild(bitmap);
var sprite = new LSprite();
sprite.graphics.drawRect(3, "#000000", [0, 0, 190, 100],true,"#00FF00");
sprite.x = -100;
layer.addChild(sprite);
layer.cacheAsBitmap(true);

callParent

(
  • functionName
  • arguments
)
public

Inherited from LObject: utils/LObject.js:22

Available since 1.6.0

调用父类的函数。

Parameters:

  • functionName String

    函数名

  • arguments Array

    固定值arguments

Example:

function funA(){
    LExtends(this,LObject,[]);
}
funA.prototype.myName = function(){
    return "AAA";
}
function funB(){
    LExtends(this,funA,[]);
}
funB.prototype.myName = function(){
    return "BBB";
}
function funC(){
    LExtends(this,funA,[]);
}
funC.prototype.myName = function(){
    return this.callParent("myName",arguments);
}
LInit(1000/50,"legend",800,150,main);
function main(){
    LGlobal.setDebug(true);
    var objB = new funB();
    trace(objB.myName());//BBB
    var objC = new funC();
    trace(objC.myName());//AAA
}

clearBody

() public

Inherited from LSprite: display/LSprite.js:835

Available since 1.4.0

LBox2d相关。

移除已设定的body。

一个LSprite对象通过addBodyCircle,addBodyPolygon等方法,会将其变为一个Box2d物理世界里的一个物体,它的运动开始遵循牛顿运动定律,当调用它的clearBody()函数后,会将其变回到普通的LSprite对象,并且被加入到该对象上的body也一起被移除。

clearShape

() public

Inherited from LSprite: display/LSprite.js:679

Available since 1.9.0

清空所有碰撞形状。

Example:

var bitmapData = new LBitmapData(event.currentTarget);//width:240,height:240
var bitmap01 = new LBitmap(bitmapData);
var layer01 = new LSprite();
addChild(layer01);
layer01.addChild(bitmap01);
layer01.addShape(LShape.ARC,[110,80,60]);
layer01.addShape(LShape.RECT,[20,140,200,100]);
var rect1 = new LSprite();
rect1.x = 180;
rect1.graphics.drawRect(2,"#FF0000",[0,0,100,100]);
addChild(rect1);
trace(layer01.hitTestObject(rect1));//false
layer01.clearShape()
trace(layer01.hitTestObject(rect1));//true

clone

() LSprite public

Inherited from LSprite: display/LSprite.js:350

Available since 1.8.2

返回一个LSprite的克隆对象。

Returns:

LSprite:

一个新的 LSprite 对象,它与原始对象相同.

Example:

var circle1 = new LSprite();
circle1.graphics.drawRect(1,"#000000",[0,0,100,100],true,"#000000");
var circle2 = circle1.clone();
circle2.y = 120;
addChild(circle1);
addChild(circle2);

deleteChild

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.0.js:143

Available since 0.1.0

删除元素。

Parameters:

  • value String

    删除元素的值。

deleteChild

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.1.js:143

Available since 0.1.0

删除元素。

Parameters:

  • value String

    删除元素的值。

deleteChild

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.2.js:114

Available since 0.1.0

删除元素。

Parameters:

  • value String

    删除元素的值。

die

() public

Inherited from LSprite: display/LSprite.js:761

Available since 1.0.0

清空所有图形以及事件。

dispatchEvent

(
  • event
)
Boolean public

Inherited from LEventDispatcher: events/LEventDispatcher.js:59

Available since 1.8.0

将事件调度到事件流中。事件目标是对其调用 dispatchEvent() 方法的 LEventDispatcher 对象。

Parameters:

  • event LEvent | String

    调度到事件流中的 Event 对象。如果正在重新调度事件,则会自动创建此事件的一个克隆。在调度了事件后,其 target 属性将无法更改,因此您必须创建此事件的一个新副本以能够重新调度。

Returns:

Boolean:

如果成功调度了事件,则值为 true。

Example:

function MyEventObject(){
    var self = this;
    LExtends(self,LSprite,[]);
    self.graphics.drawRect(1,"#000000",[0,0,100,100],true,"#000000");
    self.graphics.drawRect(1,"#FF0000",[100,0,100,100],true,"#FF0000");
    self.addEventListener(LMouseEvent.MOUSE_UP,self.onclick);
    self.addEventListener(MyEventObject.CLICK_LEFT,function(event){
        trace("dispatchEvent");
    });
    self.addEventListener(MyEventObject.CLICK_RIGHT,function(event){
        trace("dispatchEvent event.name = " + event.name);
    });
}
MyEventObject.CLICK_LEFT = "click_left";
MyEventObject.CLICK_RIGHT = "click_right";
MyEventObject.prototype.onclick = function(event){
    var self = event.clickTarget;
    if(event.selfX < 100){
        self.dispatchEvent(MyEventObject.CLICK_LEFT);
    }else{
        var event = new LEvent(MyEventObject.CLICK_RIGHT);
        event.name = "LEvent Test";
        self.dispatchEvent(event);
    }
}

getBounds

(
  • targetCoordinateSpace
)
LRectangle public

Inherited from LDisplayObject: display/LDisplayObject.js:383

Available since 1.7.7

返回一个矩形,该矩形定义相对于 targetCoordinateSpace 对象坐标系的显示对象区域。

Parameters:

  • targetCoordinateSpace LDisplayObject

    定义要使用的坐标系的显示对象。

Returns:

LRectangle:

定义与 targetCoordinateSpace 对象坐标系统相关的显示对象面积的矩形。

getChildAt

(
  • index
)
LDisplayObject public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:183

Available since 1.8.0

返回位于指定索引处的子显示对象实例。

Parameters:

  • index Int

    子对象的索引位置。

Returns:

LDisplayObject:

位于指定索引位置处的子显示对象。

Example:

var container = new LSprite();
addChild(container);
var sprite1 = new LSprite();
var sprite2 = new LSprite();
var sprite3 = new LSprite();
container.addChild(sprite1);
container.addChild(sprite2);
container.addChildAt(sprite3, 0);
trace(container.getChildAt(0) == sprite3); // true
trace(container.getChildAt(1) == sprite1); // true
trace(container.getChildAt(2) == sprite2); // true

getChildByName

(
  • name
)
LDisplayObject public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:211

Available since 1.9.0

返回具有指定名称的子显示对象。如果多个子显示对象具有指定名称,则该方法会返回子级列表中的第一个对象。

getChildAt() 方法比 getChildByName() 方法快。getChildAt() 方法从缓存数组中访问子项,而 getChildByName() 方法则必须遍历链接的列表来访问子项。

Parameters:

  • name String

    要返回的子项的名称。

Returns:

LDisplayObject:

具有指定名称的子显示对象。

Example:

var container = new LSprite();
var sprite1 = new LSprite();
sprite1.name = "sprite1";
var sprite2 = new LSprite();
sprite2.name = "sprite2";
container.addChild(sprite1);
container.addChild(sprite2);
var target = container.getChildByName("sprite1");
trace(container.getChildIndex(target)); // 0

getChildIndex

(
  • child
)
Int public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:279

Available since 1.8.0

返回 LDisplayObject 的 child 实例的索引位置。

Parameters:

Returns:

Int:

要标识的子显示对象的索引位置。

Example:

var container = new LSprite();
addChild(container);
var sprite1 = new LSprite();
sprite1.name = "sprite1";
var sprite2 = new LSprite();
sprite2.name = "sprite2";
container.addChild(sprite1);
container.addChild(sprite2);
trace(container.getChildIndex(sprite1)); // 0

getDataURL

(
  • type
  • ratio
)
Base64 Image public

Inherited from LDisplayObject: display/LDisplayObject.js:472

Available since 1.7.7

将该对象转换成base64编码的image字符串。

Parameters:

  • type String

    参数type在image/png,image/jpeg,image/svg+xml等 MIME类型中选择(可以不填,默认是image/png)。

  • ratio Float

    如果是type = “image/jpeg”,可以有第二个参数,如果第二个参数ratio的值在0-1之间,则表示JPEG的质量等级,否则使用浏览器内置默认质量等级。

Returns:

Base64 Image:

base64编码的image字符串。

getHeight

() Float public

Inherited from LSprite: display/LSprite.js:277

Available since 1.0.0

获取显示对象的高度,以像素为单位。

Returns:

Float:

显示对象的高度。

Example:

var bitmapdata = new LBitmapData(event.currentTarget);  
var bitmap = new LBitmap(bitmapdata);
var layer = new LSprite();
addChild(layer);
layer.addChild(bitmap);
trace("height : " + layer.getHeight());

getParentByConstructor

(
  • constructor
)
Object public

Inherited from LDisplayObject: display/LDisplayObject.js:487

Available since 1.10.1

通过构造函数向上查找对象。

Parameters:

  • constructor Constructor

    某个构造函数

Returns:

Object:

查找到的对象。

Example:

function MyClass1(){
    base(self,LSprite,[]);
}
function MyClass2(){
    base(self,LSprite,[]);
}
var obj1 = new MyClass1();
var obj2 = new MyClass2();
var obj3 = new LSprite();
addChild(obj1);
obj1.addChild(obj2);
obj2.addChild(obj3);
trace(obj1.objectIndex == obj3.getParentByConstructor(MyClass1).objectIndex);//out: true
trace(obj2.objectIndex == obj3.getParentByConstructor(MyClass2).objectIndex);//out: true

getRootCoordinate

() LPoint public

Inherited from LDisplayObject: display/LDisplayObject.js:308

Available since 1.7.7

得到一个可显示对象相对于canvas标签左上点的坐标。

Returns:

LPoint:

一个LPoint对象。

getWidth

() Float public

Inherited from LSprite: display/LSprite.js:225

Available since 1.0.0

获取显示对象的宽度,以像素为单位。

Returns:

Float:

显示对象的宽度。

Example:

var bitmapdata = new LBitmapData(event.currentTarget);  
var bitmap = new LBitmap(bitmapdata);
var layer = new LSprite();
addChild(layer);
layer.addChild(bitmap);
trace("width : " + layer.getWidth());

globalToLocal

(
  • point
)
LPoint public

Inherited from LDisplayObject: display/LDisplayObject.js:353

Available since 1.9.11

将 point 对象从舞台(全局)坐标转换为显示对象的(本地)坐标。

要使用此方法,请先创建 LPoint 类的一个实例。您分配的 x 和 y 值表示全局坐标,因为它们是相对于主显示区域的原点 (0,0) 的。然后将 LPoint 实例作为参数传递给 globalToLocal() 方法。该方法会返回一个新的 LPoint 对象,该对象具有相对于显示对象原点(而不是舞台原点)的 x 和 y 值。

Parameters:

  • point LPoint

    用 LPoint 类创建的对象。 该 LPoint 对象指定 x 和 y 坐标作为属性。

Returns:

LPoint:

具有相对于显示对象的坐标的 LPoint 对象。

Example:

LInit(50, "legend", 800, 480, main);
function main () {
    LGlobal.setDebug(true);
    var circle = new LSprite();
    circle.x = 10;
    addChild(circle);
    var point1 = new LPoint(0, 0);
    trace(circle.globalToLocal(point1)); // [x=-10, y=0]
    var point2 = new LPoint(10, 1);
    trace(circle.globalToLocal(point2)); // [x=0, y=1]
    var point3 = new LPoint(30, 20);
    trace(circle.globalToLocal(point3)); // [x=20, y=20]
}

hasEventListener

(
  • type
)
Boolean public

Inherited from LEventDispatcher: events/LEventDispatcher.js:126

Available since 1.8.0

检查 LEventDispatcher 对象是否为特定事件类型注册了任何侦听器。这样,您就可以确定 LEventDispatcher 对象在事件流层次结构中的哪个位置改变了对事件类型的处理。

Parameters:

  • type String

    事件的类型。

Returns:

Boolean:

如果指定类型的侦听器已注册,则值为 true;否则,值为 false。

hitTestObject

(
  • obj
)
Boolean public

Inherited from LSprite: display/LSprite.js:531

Available since 1.9.0

计算显示对象的边框,以确定它是否与 obj 显示对象的边框重叠或相交。

Parameters:

Returns:

Boolean:

如果显示对象的边框相交,则为 true;否则为 false。

Example:

LGlobal.setDebug(true);
var container = new LSprite();
addChild(container);
var circle1 = new LSprite();
circle1.graphics.drawRect(1,"#000000",[0,0,100,100],true,"#000000");
var circle2 = new LSprite();
circle2.x = 120;
circle2.graphics.drawRect(1,"#FF0000",[0,0,100,100],true,"#FF0000");
var circle3 = new LSprite();
circle3.x = 60;
circle3.y = 60;
circle3.graphics.drawRect(1,"#008800",[0,0,100,100],true,"#008800");
container.addChild(circle1);
container.addChild(circle2);
container.addChild(circle3);
trace(circle1.hitTestObject(circle2));//false
trace(circle1.hitTestObject(circle3));//true
trace(circle2.hitTestObject(circle3));//true

hitTestPoint

(
  • x
  • y
)
Boolean public

Inherited from LSprite: display/LSprite.js:470

Available since 1.9.0

计算显示对象,以确定它是否与 x 和 y 参数指定的点重叠或相交。x 和 y 参数指定舞台的坐标空间中的点,而不是包含显示对象的显示对象容器中的点(除非显示对象容器是舞台)。

Parameters:

  • x Float

    要测试的此对象的 x 坐标。

  • y Float

    要测试的此对象的 y 坐标。

Returns:

Boolean:

如果显示对象与指定的点重叠或相交,则为 true;否则为 false。

Example:

LInit(20,"legend",800,450,main);
var backLayer;
var title;
function main(){
    backLayer = new LSprite();
    addChild(backLayer);
    backLayer.addEventListener(LEvent.ENTER_FRAME,onframe);
    title = new LTextField();
    title.size = 18;
    title.x = 10;
    title.y = 5;
    title.text = "hitTestPoint:false";
    addChild(title);
    var layer = new LSprite();
    layer.x = 20;
    layer.y = 50;
    layer.graphics.drawRect(0,"#880088",[0,0,100,40],true,"#880088");
    layer.addShape(LShape.RECT,[0,0,100,40]);
    backLayer.addChild(layer);
    layer = new LSprite();
    layer.x = 200;
    layer.y = 100;
    layer.graphics.drawArc(0,"#880088",[0,0,30,0,2*Math.PI],true,"#880088");
    layer.addShape(LShape.ARC,[0,0,30]);
    backLayer.addChild(layer);
    layer = new LSprite();
    layer.x = 120;
    layer.y = 150;
    layer.graphics.drawVertices(0,"#880088",[[10,10],[50,100],[100,70]],true,"#880088");
    layer.addShape(LShape.VERTICES,[[10,10],[50,100],[100,70]]);
    backLayer.addChild(layer);
}
function onframe(e){
    for(var i=0;i<backLayer.childList.length;i++){
        if(backLayer.childList[i].hitTestPoint(mouseX,mouseY)){
            title.text = "hitTestPoint:true";
            return;
        }
    }
    title.text = "hitTestPoint:false";
}

localToGlobal

(
  • point
)
LPoint public

Inherited from LDisplayObject: display/LDisplayObject.js:318

Available since 1.9.11

将 point 对象从显示对象的(本地)坐标转换为舞台(全局)坐标。

此方法允许您将任何给定的 x 和 y 坐标从相对于特定显示对象原点 (0,0) 的值(本地坐标)转换为相对于舞台原点的值(全局坐标)。

要使用此方法,请先创建 Point 类的一个实例。您分配的 x 和 y 的值表示本地坐标,因为它们是相对于显示对象原点的值。

然后,您可以将创建的 Point 实例作为参数传递给 localToGlobal() 方法。该方法会返回一个新的 Point 对象,该对象具有相对于舞台原点(而不是显示对象原点)的 x 和 y 值。

Parameters:

  • point LPoint

    使用 Point 类创建的点的名称或标识符,指定 x 和 y 坐标作为属性。

Returns:

LPoint:

具有相对于舞台的坐标的 Point 对象。

Example:

LInit(50, "legend", 800, 480, main);
var square;
function main () {
    LGlobal.setDebug(true);
    square = new LSprite();
    square.graphics.drawRect(1,"#000000",[0, 0, 100, 100]);
    square.x = 100;
    square.y = 200;
    addChild(square);
    square.addEventListener(LMouseEvent.MOUSE_DOWN, traceCoordinates);
}
function traceCoordinates(event) {
    var clickPoint = new LPoint(mouseX, mouseY);
    trace("display object coordinates:", clickPoint);
    trace("stage coordinates:", square.localToGlobal(clickPoint));
}

remove

() public

Inherited from LDisplayObject: display/LDisplayObject.js:602

Available since 1.7.7

将对象自己从父容器中移除。

removeAllChild

()

从 LDisplayObjectContainer 实例的子列表中删除所有的 child LDisplayObject 实例。

removeAllEventListener

() public

Inherited from LEventDispatcher: events/LEventDispatcher.js:50

Available since 1.8.0

从 LEventDispatcher 对象中删除所有侦听器。

removeChild

(
  • child
)
LDisplayObject public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:145

Available since 1.0.0

从 LDisplayObjectContainer 实例的子列表中删除指定的 child LDisplayObject 实例。将已删除子项的 parent 属性设置为 null;如果不存在对该子项的任何其它引用,则将该对象作为垃圾回收。LDisplayObjectContainer 中该子项之上的任何显示对象的索引位置都减去 1。

Parameters:

Returns:

LDisplayObject:

在 child 参数中传递的 LDisplayObject 实例。

Example:

function main () {
    var container = new LSprite();
    addChild(container);
    var circle1 = new LSprite();
    circle1.graphics.drawRect(1,"#000000",[0,0,50,50]);
    var circle2 = new LSprite();
    circle2.graphics.drawRect(1,"#000000",[100,100,50,50]);
    container.addChild(circle1);
    container.addChild(circle2);
    container.addEventListener(LMouseEvent.MOUSE_DOWN, clicked);
}
function clicked (event) {
    event.currentTarget.removeChild(event.target);
}

removeChildAt

(
  • index
)
LDisplayObject public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:243

Available since 1.8.0

从 LDisplayObjectContainer 的子列表中指定的 index 位置删除子 LDisplayObject。将已删除子项的 parent 属性设置为 null;如果没有对该子项的任何其他引用,则将该对象作为垃圾回收。LDisplayObjectContainer 中该子项之上的任何显示对象的索引位置都减去 1。

Parameters:

  • index Int

    要删除的 DisplayObject 的子索引。

Returns:

LDisplayObject:

已删除的 DisplayObject 实例。

Example:

var container = new LSprite();
addChild(container);
var sprite1 = new LSprite();
sprite1.name = "sprite1";
var sprite2 = new LSprite();
sprite2.name = "sprite2";
container.addChild(sprite1);
container.addChild(sprite2);
trace(container.numChildren) // 2
container.removeChildAt(0); 
trace(container.numChildren) // 1
trace(container.getChildAt(0).name); // sprite2

removeEventListener

(
  • type
  • listener
)
public

Inherited from LEventDispatcher: events/LEventDispatcher.js:29

Available since 1.8.0

从 LEventDispatcher 对象中删除侦听器。如果没有向 LEventDispatcher 对象注册任何匹配的侦听器,则对此方法的调用没有任何效果。

Parameters:

  • type String

    事件的类型。

  • listener Function

    要删除的侦听器对象。

setBodyMouseJoint

(
  • value
)
public

Inherited from LSprite: display/LSprite.js:781

Available since 1.4.0

LBox2d相关。

给物体添加鼠标关节,响应鼠标拖拽物体。

使用lufylegend.js引擎后,鼠标拖拽变得非常简便了,只需要调用LSprite对象的setBodyMouseJoint方法即可。

一个LSprite对象通过addBodyCircle,addBodyPolygon等方法,会将其变为一个Box2d物理世界里的一个物体,如果调用它的setBodyMouseJoint(true)函数,可以让其支持鼠标拖拽。

Parameters:

  • value Boolean

    是否支持鼠标拖拽

setChild

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.2.js:144

Available since 0.1.0

增加元素。

Parameters:

  • value String

    增加元素的值。

setChild

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.1.js:173

Available since 0.1.0

增加元素。

Parameters:

  • value String

    增加元素的值。

setChild

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.0.js:173

Available since 0.1.0

增加元素。

Parameters:

  • value String

    增加元素的值。

setChildIndex

(
  • child
  • index
)
Int public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:310

Available since 1.8.0

更改现有子项在显示对象容器中的位置。这会影响子对象的分层。例如,下例在索引位置 0、1、2 处分别显示 a、b、c 三个显示对象:

在使用 setChildIndex() 方法并指定一个已经占用的索引位置时,唯一发生更改的位置是显示对象先前的位置和新位置之间的位置。所有其他位置将保持不变。如果将一个子项移动到比它当前的索引更低的索引处,则这两个索引之间的所有子项的索引引用都将增加 1。如果将一个子项移动到比它当前的索引更高的索引处,则这两个索引之间的所有子项的索引引用都将减小 1。例如,如果上例中的显示对象容器名为 container,则可以通过调用以下代码来交换带有 a 和 b 标记的显示对象的位置:

container.setChildIndex(container.getChildAt(1), 0);

该代码产生以下对象排列:

Parameters:

  • child LDisplayObject

    要为其更改索引编号的 LDisplayObject 子实例。

  • index Int

    生成的 child 显示对象的索引编号。

Returns:

Int:

生成的 child 显示对象的索引编号。

Example:

LInit(50, "legend", 800, 480, main);
var container;
function main () {
    container = new LSprite();
    addChild(container);
    var circle1 = new LSprite();
    circle1.graphics.drawRect(1,"#000000",[0,0,100,100],true,"#000000");
    circle1.addEventListener(LMouseEvent.MOUSE_DOWN, clicked);
    var circle2 = new LSprite();
    circle2.graphics.drawRect(1,"#FF0000",[40,80,100,100],true,"#FF0000");
    circle2.addEventListener(LMouseEvent.MOUSE_DOWN, clicked);
    var circle3 = new LSprite();
    circle3.graphics.drawRect(1,"#008800",[80,0,100,100],true,"#008800");
    circle3.addEventListener(LMouseEvent.MOUSE_DOWN, clicked);
    container.addChild(circle1);
    container.addChild(circle2);
    container.addChild(circle3);
}
function clicked (event) {
    var circle = event.target;
    var topPosition = container.numChildren - 1;
    container.setChildIndex(circle, topPosition);
}

setRotate

(
  • angle
)
public

Inherited from LSprite: display/LSprite.js:109

Available since 1.4.0

使用Box2dWeb的时候,需要用setRotate来设定角度

Parameters:

  • angle Float

    角度。

setValue

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.2.js:219

Available since 0.1.0

设置组合框的值。

Parameters:

  • value String

    组合框的值。

setValue

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.1.js:283

Available since 0.1.0

设置组合框的值。

Parameters:

  • value String

    组合框的值。

setValue

(
  • value
)
public

Defined in lib/ui/LComboBox-0.1.0.js:282

Available since 0.1.0

设置组合框的值。

Parameters:

  • value String

    组合框的值。

startDrag

(
  • touchPointID
)
public

Inherited from LSprite: display/LSprite.js:141

Available since 1.8.9

允许用户拖动指定的 LSprite。LSprite 将一直保持可拖动,直到通过调用 LSprite.stopDrag() 方法来明确停止。

Parameters:

  • touchPointID Int

    分配给触摸点的整数(触摸设备)。

Example:

LInit(1000/50,"legend",800,450,main);
function main(){
    LMultitouch.inputMode = LMultitouchInputMode.TOUCH_POINT;
    for(var i=0;i<3;i++){
        var child = new LSprite();
        child.x = 250*i;
        child.graphics.drawRect(2,"#ff0000",[0,0,100,100],true,"#ff0000");
        child.addEventListener(LMouseEvent.MOUSE_DOWN,ondown);
        child.addEventListener(LMouseEvent.MOUSE_UP,onup);
        addChild(child);
    }
}
function ondown(e){
    e.clickTarget.startDrag(e.touchPointID);
}
function onup(e){
    e.clickTarget.stopDrag();
}

stopDrag

() public

Inherited from LSprite: display/LSprite.js:180

Available since 1.8.9

结束 startDrag() 方法。

Example:

LInit(1000/50,"legend",800,450,main);
function main(){
    LMultitouch.inputMode = LMultitouchInputMode.TOUCH_POINT;
    for(var i=0;i<3;i++){
        var child = new LSprite();
        child.x = 250*i;
        child.graphics.drawRect(2,"#ff0000",[0,0,100,100],true,"#ff0000");
        child.addEventListener(LMouseEvent.MOUSE_DOWN,ondown);
        child.addEventListener(LMouseEvent.MOUSE_UP,onup);
        addChild(child);
    }
}
function ondown(e){
    e.clickTarget.startDrag(e.touchPointID);
}
function onup(e){
    e.clickTarget.stopDrag();
}

Properties

alpha

Float public

Inherited from LDisplayObject: display/LDisplayObject.js:55

Available since 1.6.0

表示指定对象的 Alpha 透明度值。有效值为 0(完全透明)到 1(完全不透明)。默认值为 1。alpha 设置为 0 的显示对象是活动的,即使它们不可见。

Default: 1

blendMode

String public

Inherited from LDisplayObject: display/LDisplayObject.js:107

Available since 1.8.0

LBlendMode 类中的一个值,用于指定要使用的混合模式。 内部绘制位图的方法有两种。 如果启用了混合模式或外部剪辑遮罩,则将通过向矢量渲染器添加有位图填充的正方形来绘制位图。 如果尝试将此属性设置为无效值,运行时会将此值设置为 LBlendMode.NORMAL。

Default: null

childList

Array public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:15

Available since 1.0.0

子对象列表

dragRange

LRectangle public

Inherited from LSprite: display/LSprite.js:82

Available since 1.9.8

用户拖动该对象时的拖动范围。

LRectangle对象的x,y分别是对象可以拖动的起始坐标,width,height分别表示从起始坐标开始可以拖动的范围。

filters

Array public

Inherited from LDisplayObject: display/LDisplayObject.js:116

Available since 1.6.0

包含当前与显示对象关联的每个滤镜对象的索引数组。

Default: null

graphics

LGraphics public

Inherited from LSprite: display/LSprite.js:36

Available since 1.0.0

[只读] 指定属于此 sprite 的 LGraphics 对象,在此 sprite 中可执行矢量绘图命令。

Example:

var layer = new LSprite();
addChild(layer);
layer.graphics.drawRect(2, "#ff0000", [10, 10, 50, 100], true, "#880088");

mask

LDisplayObject public

Inherited from LDisplayObject: display/LDisplayObject.js:83

Available since 1.6.0

调用显示对象被指定的 mask 对象遮罩。要确保当舞台缩放时蒙版仍然有效,mask 显示对象必须处于显示列表的活动部分。但不绘制 mask 对象本身。将 mask 设置为 null 可删除蒙版。

Default: null

Example:

function main () {
    var loader = new LLoader();
    loader.addEventListener(LEvent.COMPLETE, loadBitmapdata); 
    loader.load("face.png", "bitmapData");
}
function loadBitmapdata (event) {
    var bitmapdata = new LBitmapData(event.target);  
    var bitmap = new LBitmap(bitmapdata);
    addChild(bitmap);
    var maskObj = new LSprite();
    maskObj.graphics.drawRect(0, "#ff0000", [10, 10, 150, 100]);
    bitmap.mask = maskObj;
}

mouseChildren

Boolean public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:46

Available since 1.9.0

确定对象的子级是否支持鼠标输入设备。

Example:

LGlobal.setDebug(true);
var container1 = new LSprite();
container1.x = container1.y = 20;
var container2 = new LSprite();
container2.x = 20;
container2.y = 100;
container2.mouseChildren = false;
addChild(container1);
addChild(container2);
var button01 = new LButtonSample1("mouseChildren=true");
container1.addChild(button01);
button01.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
    trace("button01 click");
});
var button02 = new LButtonSample1("mouseChildren=false");
container2.addChild(button02);
button02.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
    trace("button02 click");
});

mouseEnabled

Boolean public

Inherited from LInteractiveObject: display/LInteractiveObject.js:14

Available since 1.8.10

指定此对象是否接收鼠标或其他用户输入、消息。默认值为 true,这表示默认情况下,显示列表上的任何 LInteractiveObject 实例都会接收鼠标事件或其他用户输入事件。如果将 mouseEnabled 设置为 false,则实例将不接收任何鼠标事件(或其他用户输入事件,例如键盘事件)。显示列表上的该实例的任何子级都不会受到影响。要更改显示列表上对象的所有子级的 mouseEnabled 行为,请使用 LDisplayObjectContainer.mouseChildren。

Example:

LGlobal.setDebug(true);
var button01 = new LButtonSample1("mouseEnabled=true");
button01.x = button01.y = 20;
addChild(button01);
button01.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
    trace("button01 click");
});
var button02 = new LButtonSample1("mouseEnabled=false");
button02.x = 20;
button02.y = 150;
button02.mouseEnabled = false;
addChild(button02);
button02.addEventListener(LMouseEvent.MOUSE_DOWN,function(e){
    trace("button02 click");
});

numChildren

Int public

Inherited from LDisplayObjectContainer: display/LDisplayObjectContainer.js:23

Available since 1.9.0

返回此对象的子项数目。

Example:

var container1 = new LSprite();
var container2 = new LSprite();
var circle1 = new LSprite();
circle1.graphics.drawRect(1,"#000000",[0,0,50,50]);
var circle2 = new LSprite();
circle2.graphics.drawRect(1,"#000000",[100,100,50,50]);
container2.addChild(container1);
container1.addChild(circle1);
container1.addChild(circle2);
trace(container1.numChildren); // 2
trace(container2.numChildren); // 1
trace(circle1.numChildren); // 0
trace(circle2.numChildren); // 0

objectIndex

Int public

Inherited from LObject: utils/LObject.js:11

Available since 1.6.0

对象的ID

parent

LDisplayObjectContainer public

Inherited from LDisplayObject: display/LDisplayObject.js:148

Available since 1.0.0

[只读] 表示包含此显示对象的 DisplayObjectContainer 对象。

使用 parent 属性可以指定高于显示列表层次结构中当前显示对象的显示对象的相对路径。

可以使用 parent 在显示列表中上移多个级别,如下所示:

this.parent.parent.x = 20;

Example:

var sprite1 = new LSprite();
sprite1.name = "sprite1";
var sprite2 = new LSprite();
sprite2.name = "sprite2";
var sprite3 = new LSprite();
sprite3.name = "sprite3";
sprite1.addChild(sprite2);
sprite2.addChild(sprite3);
trace(sprite2.parent.name); // sprite1
trace(sprite3.parent.name); // sprite2
trace(sprite3.parent.parent.name); // sprite1

rotate

Float public

Inherited from LDisplayObject: display/LDisplayObject.js:74

Available since 1.6.0

表示 LDisplayObject 实例距其原始方向的旋转程度,以度为单位。从 0 到 180 的值表示顺时针方向旋转;从 0 到 -180 的值表示逆时针方向旋转。对于此范围之外的值,可以通过加上或减去 360 获得该范围内的值。例如,my_video.rotate = 450语句与 my_video.rotate = 90 是相同的。

Default: 0

scaleX

Float public

Inherited from LDisplayObject: display/LDisplayObject.js:37

Available since 1.6.0

表示从注册点开始应用的对象的水平缩放比例(百分比)。默认注册点为 (0,0)。1.0 等于 100% 缩放。

Default: 1

scaleY

Float public

Inherited from LDisplayObject: display/LDisplayObject.js:46

Available since 1.6.0

表示从对象注册点开始应用的对象的垂直缩放比例(百分比)。默认注册点为 (0,0)。1.0 是 100% 缩放。

Default: 1

selectIndex

String public

Defined in lib/ui/LComboBox-0.1.0.js:23

Available since 0.1.0

[只读]组合框的值的索引

selectIndex

String public

Defined in lib/ui/LComboBox-0.1.1.js:23

Available since 0.1.0

[只读]组合框的值的索引

selectIndex

String public

Defined in lib/ui/LComboBox-0.1.2.js:23

Available since 0.1.0

[只读]组合框的值的索引

shapes

Array public

Inherited from LSprite: display/LSprite.js:51

Available since 1.9.0

用于碰撞的形状列表

Example:

function loadBitmapdata (event) {
    var bitmapdata = new LBitmapData(event.currentTarget); 
    var bitmap = new LBitmap(bitmapdata);

    layer = new LSprite();
    layer.addChild(bitmap);
    layer.x = 20;
    layer.y = 50;
    layer.addShape(LShape.VERTICES, [[180, 20], [210, 40], [210, 60], [120, 110], [35, 100]]);
    layer.addShape(LShape.VERTICES, [[120, 110], [140, 120], [140, 150], [110, 160], [35, 120], [35, 100]]);
    addChild(layer);

    layer.addEventListener(LEvent.ENTER_FRAME, onframe);
}
function onframe (e) {
    if (layer.hitTestPoint(mouseX, mouseY)) {
        layer.alpha = 0.5;
    } else {
        layer.alpha = 1;
    }
}

transform

LTransform public

Inherited from LDisplayObject: display/LDisplayObject.js:125

Available since 1.9.8

一个对象,具有与显示对象的矩阵有关的属性。在 LTransform 类的条目中对特定属性 matrix 进行了说明。

transform 对象的每个属性本身都是一个对象。此概念很重要,因为设置 matrix 对象的新值的唯一方法是,创建新对象并将该对象复制到 transform.matrix 属性。

Example:

function main () {
    var square = new LSprite();
    square.graphics.drawRect(1, "#ff0000", [0, 0, 150, 100],true);
    addChild(square);
    square.addEventListener(LMouseEvent.MOUSE_UP, transformer);
}
function transformer(event) {
    var square = event.currentTarget;
    var tempMatrix = new LMatrix();
    tempMatrix.skew(0.3, 0).translate(30,50);
    square.transform.matrix = tempMatrix;
}

type

String public

Inherited from LSprite: display/LSprite.js:25

Available since 1.0.0

对象的类型

Default: LSprite

useCursor

String public

Inherited from LSprite: display/LSprite.js:91

Available since 1.9.10

表示当指针滑过sprite时是否显示的指针光标。

Default: null

Example:

var layer01 = new LSprite();
layer01.useCursor = "pointer";
addChild(layer01);
var bm01 = new LBitmap(new LBitmapData("#FF0000", 0, 0, 100, 100));
layer01.addChild(bm01);

value

String public

Defined in lib/ui/LComboBox-0.1.1.js:31

Available since 0.1.0

[只读]组合框的值

value

String public

Defined in lib/ui/LComboBox-0.1.0.js:31

Available since 0.1.0

[只读]组合框的值

value

String public

Defined in lib/ui/LComboBox-0.1.2.js:31

Available since 0.1.0

[只读]组合框的值

visible

Boolean public

Inherited from LDisplayObject: display/LDisplayObject.js:65

Available since 1.6.0

显示对象是否可见。不可见的显示对象已被禁用。例如,如果 LInteractiveObject 实例的 visible=false,则无法单击该对象。

Default: true

x

Float public

Inherited from LDisplayObject: display/LDisplayObject.js:17

Available since 1.6.0

表示 LDisplayObject 实例相对于父级 LDisplayObjectContainer 本地坐标的 x 坐标。如果该对象位于具有变形的 LDisplayObjectContainer 内,则它也位于包含 LDisplayObjectContainer 的本地坐标系中。因此,对于逆时针旋转 90 度的 LDisplayObjectContainer,该 LDisplayObjectContainer 的子级将继承逆时针旋转 90 度的坐标系。对象的坐标指的是注册点的位置。

Default: 0

y

Float public

Inherited from LDisplayObject: display/LDisplayObject.js:26

Available since 1.6.0

表示 LDisplayObject 实例相对于父级 LDisplayObjectContainer 本地坐标的 y 坐标。如果该对象位于具有变形的 LDisplayObjectContainer 内,则它也位于包含 LDisplayObjectContainer 的本地坐标系中。因此,对于逆时针旋转 90 度的 LDisplayObjectContainer,该 LDisplayObjectContainer 的子级将继承逆时针旋转 90 度的坐标系。对象的坐标指的是注册点的位置。

Default: 0

Events

LComboBox.ON_CHANGE

Defined in lib/ui/LComboBox-0.1.0.js:107

Available since 0.1.0

组合框的值改变时调用此事件。

LComboBox.ON_CHANGE

Defined in lib/ui/LComboBox-0.1.2.js:108

Available since 0.1.0

组合框的值改变时调用此事件。

LComboBox.ON_CHANGE

Defined in lib/ui/LComboBox-0.1.1.js:107

Available since 0.1.0

组合框的值改变时调用此事件。

LEvent.ADDED

将显示对象添加到显示列表中时调度。以下方法会触发此事件:LDisplayObjectContainer.addChild()、LDisplayObjectContainer.addChildAt()。

使用时需要引入lufylegend.LEvent.added-x.x.x.min.js文件。

LEvent.ADDED

LEvent.ADDED_TO_STAGE

在将显示对象直接添加到舞台显示列表或将包含显示对象的子树添加至舞台显示列表中时调度。以下方法会触发此事件:LDisplayObjectContainer.addChild()、LDisplayObjectContainer.addChildAt()。

使用时需要引入lufylegend.LEvent.added-x.x.x.min.js文件。

LEvent.ADDED_TO_STAGE

LEvent.ENTER_FRAME

[播放事件] 播放头进入新帧时调度。

LEvent.ENTER_FRAME

LEvent.REMOVED

将要从显示列表中删除显示对象时调度。LDisplayObjectContainer 类的以下两个方法会生成此事件:removeChild() 和 removeChildAt()。

使用时需要引入lufylegend.LEvent.added-x.x.x.min.js文件。

LEvent.REMOVED

LEvent.REMOVED_FROM_STAGE

在从显示列表中直接删除显示对象或删除包含显示对象的子树时调度。LDisplayObjectContainer 类的以下两个方法会生成此事件:removeChild() 和 removeChildAt()。

使用时需要引入lufylegend.LEvent.added-x.x.x.min.js文件。

LEvent.REMOVED_FROM_STAGE

LMouseEvent.DOUBLE_CLICK

当用户在LInteractiveObject 实例上快速连续按下两次并释放指针设备的主按钮时调度。

LMouseEvent.DOUBLE_CLICK

LMouseEvent.MOUSE_DOWN

当用户在 LInteractiveObject 实例上按下指针设备按钮时调度。

LMouseEvent.MOUSE_DOWN

LMouseEvent.MOUSE_MOVE

用户移动 LInteractiveObject 上的指针设备时调度。

LMouseEvent.MOUSE_MOVE

LMouseEvent.MOUSE_OUT

用户将指针设备从 LInteractiveObject 实例上移开时调度。

LMouseEvent.MOUSE_OUT

LMouseEvent.MOUSE_OVER

用户将指针设备移动到 LInteractiveObject 实例上时调度。

LMouseEvent.MOUSE_OVER

LMouseEvent.MOUSE_UP

当用户在 LInteractiveObject 实例上释放指针设备按钮时调度。

LMouseEvent.MOUSE_UP