CocosCreator 源码cc.MoveTo详解

欢迎关注公众号:“Cocos Creator 源码讲解”,一起学习。

/*
 * Moves a Node object to the position x,y. x and y are absolute coordinates by modifying its position property. <br/>
 * Several MoveTo actions can be concurrently called, and the resulting                                            <br/>
 * movement will be the sum of individual movements.
 * @class MoveTo
 * @extends MoveBy
 * @param {Number} duration duration in seconds
 * @param {Vec2|Number} position
 * @param {Number} [y]
 * @example
 * var actionBy = new cc.MoveTo(2, cc.v2(80, 80));
 */
/*
 * 将 Node 对象移动到位置 x,y。通过修改其position属性,x和y为绝对坐标。 <br/>
 * 可以同时调用多个 MoveTo 操作,结果<br/>
 * 运动将是个体运动的总和。
 * @类移动到
 * @extends MoveBy
 * @param {Number} 持续时间 持续时间(以秒为单位)
 * @param {Vec2|Number} 位置
 * @param {数字} [y]
 * @例子
 * var actionBy = new cc.MoveTo(2, cc.v2(80, 80));
 */
cc.MoveTo = cc.Class({
    name: 'cc.MoveTo',
    extends: cc.MoveBy,

    ctor: function (duration, position, y) {
        this._endPosition = cc.v2(0, 0);
        position !== undefined && this.initWithDuration(duration, position, y);
    },

    /*
     * Initializes the action.
     * @param {Number} duration  duration in seconds
     * @param {Vec2} position
     * @param {Number} [y]
     * @return {Boolean}
     */
    /* /*
     * 初始化操作。
     * @param {Number} 持续时间 持续时间(以秒为单位)
     * @param {Vec2} 位置
     * @param {数字} [y]
     * @return {布尔值}
     */ */
    initWithDuration: function (duration, position, y) {
        if (cc.MoveBy.prototype.initWithDuration.call(this, duration, position, y)) {
            /* 根据参数个数,进行重新定义第二个和第三个参数 */
            if (position.x !== undefined) {
                y = position.y;
                position = position.x;
            }

            this._endPosition.x = position;
            this._endPosition.y = y;
            return true;
        }
        return false;
    },
    /* 复制Action */
    clone: function () {
        var action = new cc.MoveTo();
        this._cloneDecoration(action);
        action.initWithDuration(this._duration, this._endPosition);
        return action;
    },
    /* target 赋值 */
    startWithTarget: function (target) {
        cc.MoveBy.prototype.startWithTarget.call(this, target);
        this._positionDelta.x = this._endPosition.x - target.x;
        this._positionDelta.y = this._endPosition.y - target.y;
    }
});

/**
 * !#en
 * Moves a Node object to the position x,y. x and y are absolute coordinates by modifying its position property. <br/>
 * Several MoveTo actions can be concurrently called, and the resulting                                            <br/>
 * movement will be the sum of individual movements.
 * !#zh 移动到目标位置。
 * @method moveTo
 * @param {Number} duration duration in seconds
 * @param {Vec2|Number} position
 * @param {Number} [y]
 * @return {ActionInterval}
 * @example
 * // example
 * var actionBy = cc.moveTo(2, cc.v2(80, 80));
 */
/* 创建一个 moveTo对象  */
cc.moveTo = function (duration, position, y) {
    return new cc.MoveTo(duration, position, y);
};

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值