cocoscreator 抖动动画

// 抖动 动画
cc.Shake = cc.ActionInterval.extend({
    _initial_x : 0,
    _initial_y : 0,
    _strength_x : 0,
    _strength_y : 0,
    /**
     *  创建抖动动画
     * @param {number} duration     动画持续时长
     * @param {number} strength_x   抖动幅度: x方向
     * @param {number} strength_y   抖动幅度: y方向
     * @returns {Shake}
     */
    ctor:function(duration,strength_x,strength_y){
        cc.ActionInterval.prototype.ctor.call(this);
        this.initWithDuration( duration,strength_x,strength_y);
    },
    initWithDuration(duration,strength_x,strength_y) {
        cc.ActionInterval.prototype.initWithDuration.call(this, duration)
        this._strength_x = strength_x;
        this._strength_y = strength_y;
        return true;
    },
    update()
    {
        let randx = Math.randomInt(-this._strength_x,this._strength_x);
        let randy = Math.randomInt(-this._strength_y,this._strength_y);
        this.getTarget().setPosition(randx + this._initial_x,randy + this._initial_y);
    },
    startWithTarget(target)
    {
        cc.ActionInterval.prototype.startWithTarget.call(this, target);
        this._initial_x = target.x;
        this._initial_y = target.y;
    },
    stop()
    {
        this.getTarget().setPosition(new cc.Vec2(this._initial_x,this._initial_y));
        cc.ActionInterval.prototype.stop.call(this);
    },
});
cc.shake = function (duration,strength_x,strength_y) {
    return new cc.Shake(duration,strength_x,strength_y);
};

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值