lufy's legend

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
123
返回列表 发新帖
楼主: 陈前帆
打印 上一主题 下一主题

核心改进文件1

[复制链接]

14

主题

0

好友

132

积分

士兵

Rank: 1

沙发
发表于 2013-11-29 12:51:54 |只看该作者
/**
* 全局对象累的,此类在。
* @class  LGlobal
*/

/**
* LGlobal.mouseEvent
*
* @static
* @method mouseEvent
* @param {LMouseEvent} e 鼠标事件。
* @param {String}      t 事件类型。
*/
LGlobal.mouseEvent = function(e, t) {
    //console.log("core.js -> LGlobal.mouseEvent(e, t) e.type = " + e.type);
    e.type = t;
    var k = null;
    for (k = LGlobal.childList.length - 1; k >= 0; k--) {
        if (LGlobal.childList[k].mouseEvent) {
            if(LGlobal.childList[k].mouseEvent(e, t)){
                break;
            }
        }
    }
};

/**
* lufylegend-1.8.1 类 LEventDispatcher
* @method LEventDispatcher
*/

/**
* LEventDispatcher.addEventListener(type, listener),添加一个事件侦听器。
* @method addEventListener
* @param {String}              type               事件类型
* @param {Function|Delegate}   listener           事件侦听器,一个事件处理函数或者一个事件委托。
*/
//LEventDispatcher.prototype.addEventListener=function(type,listener){
//    this._eventList.push({listener:listener,type:type});
//};

/**
* 【重写函数】LEventDispatcher.removeEventListener(type,listener)
* @method removeEventListener
* @param {String}              type               事件类型。
* @param {Function|Delegate}   [listener=null]    事件侦听器,一个事件处理函数或者一个事件委托。
*/
LEventDispatcher.prototype.removeEventListener=function(type,listener){
    var s = this,i,length;
    this._removeEventListener(type, s._eventList, listener);
};

/**
* @method
*
*/
/**
* 使用本方法来删除指定事件类型的事件。
* @method _removeEventListener
* @param {String}              type        事件类型。
* @param {Array}               eventList   事件侦听记录表。
* @param {Function|Delegate}   listener    事件侦听器类型为:Function or Delegate
* @private
*/
LEventDispatcher.prototype._removeEventListener = function(type, eventList, listener) {
    length = eventList.length;
    var item;
    for(i=0;i<length;i++){
        item = eventList[i];
        if(type == item.type && item.listener == listener){
            eventList.splice(i,1);
            return ;
        }else if(type == item.type &&
            listener instanceof Delegate &&
            item.listener instanceof Delegate &&
            item.listener.isEqual(listener)
            ){
            item.listener.dispose();
            listener.dispose();
            eventList.splice(i,1);
            return ;
        }
    }
};

/**
* LEventDispatcher.removeAllEventListener() 移除对象所有侦听。
* @method removeAllEventListener
*/
//LEventDispatcher.prototype.removeAllEventListener=function (){
//    this._eventList = [];
//};
/**
* 【重写函数】 LEventDispatcher.dispatchEvent(eventType|eventObject)
* @method dispatchEvent
* @param {String|BEvent} type 本参数可以是一个String类型的 eventType,也可以是一个 eventObject 的引用。
*/
LEventDispatcher.prototype.dispatchEvent=function(type){
    //console.log("lufylegend-1.8.1.js dispatchEvent(type) type = " + type);
    var s = this;
    var i,length = s._eventList.length;
    var listener;
    var event;
    var o;
    //组件原始方法。
    if(typeof type === "string"){
        //console.log("core-lufylegend-1.8.1.js dispatchEvent(type) type = " + type);
        for(i=0;i<length;i++){
            if(type == s._eventList[i].type){
                s.target = s;
                s.event_type = type;
                //s._eventList[i].listener(s);
                o = s._eventList[i];
                //console.log("core-lufylegend-1.8.1.js dispatchEvent(type) o.listener instanceof Function = " + (o.listener instanceof Function));
                if(o.listener instanceof Function){
/*                    try{*/
                        o.listener.apply(this, [s]);
/*                   }catch(err){
                        trace(this + ".dispatchEvent(type) [s] = "+ [s] + " -->错误名称:" + err.name + ", \n错误信息:" + err.message);
                    }*/
                }else if(o.listener instanceof Delegate){
                    o.listener.run([s]);
                }
                //return;
            }
        }
    }else {
        //使用抛出事件
        event = type;
        if(typeof event.type === "string"){
            for(i=0;i<length;i++){
                if(event.type == s._eventList[i].type){
                    event.currentTarget = s;
                    o = s._eventList[i];
                    //console.log("core-lufylegend-1.8.1.js dispatchEvent(type) o.listener instanceof Function = " + (o.listener instanceof Function));
                    if(o.listener instanceof Function){
                        o.listener.apply(this, [event]);
                    }else if(o.listener instanceof Delegate){
                        o.listener.run([event]);
                    }
                    //return;
                }
            }
        }
    }

};
/**
* LEventDispatcher.hasEventListener(type) 检查是否添加了指定类型的事件侦听。
* @method hasEventListener
* @param {String} type
* @returns {boolean}
*/
//LEventDispatcher.prototype.hasEventListener=function(type){
//    var s = this,i,length = s._eventList.length;
//    for(i=0;i<length;i++){
//        if(type == s._eventList[i].type)return true;
//    }
//    return false;
//};

//输出窗口提示。
{
    console.log("注意:现使用 core.js 重写的 LSprite.mouseEvent(e, type, cd) 函数!");
}


/**
* @class LDisplayObject
* @returns {LPoint}
*/

/**
* @method getRootCoordinate
* @returns {LPoint}
*/
LDisplayObject.prototype.getRootCoordinate = function(){
    var s = this;
    var sx=s.x,sy=s.y;
    var p = s.parent;
    while(p != "root"){
        sx *= p.scaleX;
        sy *= p.scaleY;
        sx += p.x;
        sy += p.y;
        p = p.parent;
    }
    return new LPoint(sx,sy);
};
回复

使用道具 举报

14

主题

0

好友

132

积分

士兵

Rank: 1

楼主
发表于 2013-11-29 12:51:31 |只看该作者
/**
* 此类在 core.js 中进行扩展,扩展自 lufylegend-1.7.7 : LPoint 类
* @class LPoint
*/


/**
* [静态] 返回 pt1 和 pt2 之间的距离。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
*
* @static
* @method distance
* @param {LPoint} pt1
* @param {LPoint} pt2
* @return {Number}
*/
LPoint.distance = function (pt1, pt2){
    return LPoint.distance2(pt1.x, pt1.y, pt2.x, pt2.y);
};

/**
* [静态] 返回点 x1,y1 和点 x2,y2 之间的距离。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
*
* @method distance2
* @param {Number} x1 第一点的 x 轴。
* @param {Number} y1 第一点的 y 轴。
* @param {Number} x2 第二点的 x 轴
* @param {Number} y2 第二点的 y 轴。
* @return {Number}
*/
LPoint.distance2 = function(x1, y1, x2, y2){
    //最佳方法为。
    var x = x1 - x2;
    var y = y1 - y2;
    return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
};

/**
* [静态] 确定两个指定点之间的点。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
*
* @static
* @method interpolate
* @param {LPoint} pt1 第一个点。
* @param {LPoint} pt2 第二个点。
* @param {Number} f  两个点之间的内插级别。表示新点将位于 pt1 和 pt2 连成的直线上的什么位置。
*                     如果 f=1,则返回 pt1;如果 f=0,则返回 pt2。
* @return {LPoint}
*/
LPoint.interpolate = function(pt1, pt2, f){
    var _x = pt2.x - pt1.x;
    var _y = pt2.y - pt1.y;
    var tanVal = _y / _x;
    var radians = Math.atan(tanVal);//获得角弧度。
    var sinVal = Math.sin(radians);
    var length =  _y / sinVal;
    length *= f;
    var newY = length * sinVal;
    var newX = newY / tanVal;
    return new LPoint(newX, newY);
};



/**
* [静态] 将一对极坐标转换为笛卡尔点坐标。* 未实现 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @static
* @method polar
* @param {Number} len 极坐标对的长度。
* @param {Number} angle 极坐标对的角度(以弧度表示)。
* @return {LPoint}
*/
LPoint.polar = function (len, angle){
    return new LPoint(0,0);
};

/**
* 按指定量偏移 Point 对象。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method offset
* @param {Number} dx
* @param {Number} dy
* @return {void}
*/
LPoint.prototype.offset = function(dx, dy){
    this.x += dx;
    this.y += dy;
};

/**
* 将 Point 的成员设置为指定值。 * 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method setTo
* @param {Number} xa
* @param {Number} ya
* @return {void}
*/
LPoint.prototype.setTo = function(xa, ya){
    this.x = xa;
    this.y = ya;
};

/**
* 从 (0,0) 到此点的线段长度。
* @method getLength
* @return {Number}
*/
LPoint.prototype.getLength = function(){
    return LPoint.distance(LPoint.EMPTY, this);
};

/**
* 创建此 LPoint 对象的副本。
* @method  clone
* @return {LPoint}
*/
LPoint.prototype.clone = function(){
    return new LPoint(this.x, this.y);
};


/**
* 将另一个点的坐标添加到此点的坐标以创建一个新点。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method add
* @param {LPoint} v
* @return {LPoint}
*/
LPoint.prototype.add = function(v){
    return new LPoint(this.x + v.x, this.y + v.y);
};


/**
* 从此点的坐标中减去另一个点的坐标以创建一个新点。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method subtract
* @param {LPoint} v
* @return {LPoint}
*/
LPoint.prototype.subtract = function(v){
    return new LPoint(this.x - v.x, this.y - v.y);
};

/**
* 确定两个点是否相同。* 扩展 lufylegend-1.7.7 LPoint 类。 *
* @method equals
* @param {LPoint} toCompare
* @return Boolean
*/
LPoint.prototype.equals = function(toCompare){
    return (this.x == toCompare.x && this.y == toCompare.y);
};

/**
* 将源 LPoint 对象中的所有点数据复制到调用方 LPoint 对象中。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method copyFrom
* @param {LPoint} sourcePoint
* @return {void}
*/
LPoint.prototype.copyFrom = function(sourcePoint){
    this.setTo(sourcePoint.x, sourcePoint.y);
};

/**
* 将 (0,0) 和当前点之间的线段缩放为设定的长度。* 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @method normalize
* @param {Number} thickness 缩放值。例如,如果当前点为 (0,5) 并且您将它规范化为 1,则返回的点位于 (0,1) 处。
* @return {void}
*/
LPoint.prototype.normalize = function (thickness){
    var pt1 = LPoint.EMPTY;
    var _x = this.x - pt1.x;
    var _y = this.y - pt1.y;
    var tanVal = _y / _x;
    var radians = Math.atan(tanVal);//获得角弧度。
    var sinVal = Math.sin(radians);
    this.y = thickness * sinVal;
    this.x = this.y / tanVal;
};

/**
* 一个全局静态的点,值为 x = 0, y = 0。注意: 请不要更改此对象的属性。 * 扩展 lufylegend-1.7.7 : LPoint 类。 *
* @static
* @property EMPTY
* @type {LPoint}
*/
LPoint.EMPTY = new LPoint(0,0);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

防止垃圾广告,请填写任意字符

Archiver|lufy's legend

GMT+8, 2024-5-20 12:11 , Processed in 0.048793 second(s), 18 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部