pubgv3/assets/scripts/tools/CCActionAdd.js
zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

130 lines
4.0 KiB
JavaScript

cc.ShakeAction = cc.ActionInterval.extend({
// ctor:function (duration, strength ) {
// // cc.ActionInterval.prototype.ctor.call(this);
// this.initWithDuration(duration, strength );
// },
initWithDuration:function (duration, strengthx, strengthy) { //function overload here
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
this._strengthx = strengthx ;
this._strengthy = strengthy ;
return true;
}
return false;
},
clone:function () {
var action = new cc.ShakeAction();
this._cloneDecoration(action);
action.initWithDuration(this._duration, this._strength);
return action;
},
startWithTarget:function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
this.oldPos = this.target.position;
},
fgRangeRand(min,max){
var rnd = Math.random();
return rnd*(max-min)+min;
},
stop(){
if(this.target&&this.oldPos){
this.target.position = this.oldPos;
}
this.target = null;
this.oldPos = null;
},
update:function (dt) {
//dt = this._computeEaseTime(dt);
var randx = this.fgRangeRand( -this._strengthx, this._strengthx )*dt;
var randy = this.fgRangeRand( -this._strengthy, this._strengthy )*dt;
if (this.target) {
var pos = this.target.position;
pos.x = pos.x+randx;
pos.y = pos.y+randy;
this.target.position = pos;
}
}
});
cc.ProgressTo = cc.ActionInterval.extend({
// ctor:function (duration, start, end) {
// cc.ActionInterval.prototype.ctor.call(this);
// this.initWithDuration(duration, start, end);
// },
initWithDuration:function (duration, start, end) { //function overload here
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
this._start = start;
this._end = end;
return true;
}
return false;
},
clone:function () {
var action = new cc.ProgressTo();
this._cloneDecoration(action);
action.initWithDuration(this._duration, this._start, this._end);
return action;
},
startWithTarget:function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
this.progress = this.target.getComponent('cc.ProgressBar');
this.progress.progress = this._start;
this._delta = this._end - this._start;
},
update:function (dt) {
dt = this._computeEaseTime(dt);
if (this.target) {
this.progress.progress = this._start + this._delta * dt;
}
}
});
cc.VauleTo = cc.ActionInterval.extend({
// ctor:function (duration, start, end,callback) {
// // cc.ActionInterval.prototype.ctor.call(this);
// this.initWithDuration(duration, start, end ,callback);
// },
initWithDuration:function (duration, start, end,callback) { //function overload here
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
this._start = start;
this._end = end;
this._callback = callback;
return true;
}
return false;
},
clone:function () {
var action = new cc.VauleTo();
this._cloneDecoration(action);
action.initWithDuration(this._duration, this._start, this._end,this._callback);
return action;
},
startWithTarget:function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);;
this._delta = this._end - this._start;
},
update:function (dt) {
dt = this._computeEaseTime(dt);
if (this.target&&this._callback) {
this._callback(this._start+this._delta * dt);
}
}
});