Commit cfd099d5 authored by rockyl's avatar rockyl

loop实现

parent 058b046d
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* 波动组件 * 波动组件
*/ */
import {ScillaComponent, raw} from "scilla"; import {ScillaComponent, raw, ScillaEvent} from "scilla";
const PI2 = Math.PI * 2; const PI2 = Math.PI * 2;
...@@ -50,10 +50,14 @@ export default class Wave extends ScillaComponent { ...@@ -50,10 +50,14 @@ export default class Wave extends ScillaComponent {
loop: number = -1; loop: number = -1;
autoPlay: boolean = true; autoPlay: boolean = true;
onComplete: ScillaEvent = new ScillaEvent();
onLoopComplete: ScillaEvent = new ScillaEvent();
private _playing; private _playing;
private _waveMethod; private _waveMethod;
private _startTime; private _startTime;
private _oldProps: any = {}; private _oldProps: any = {};
private _loopCounting;
onAwake() { onAwake() {
super.onAwake(); super.onAwake();
...@@ -80,8 +84,16 @@ export default class Wave extends ScillaComponent { ...@@ -80,8 +84,16 @@ export default class Wave extends ScillaComponent {
const {duration, waveParams, _waveMethod, transform, transform: {position, scale}, _oldProps} = this; const {duration, waveParams, _waveMethod, transform, transform: {position, scale}, _oldProps} = this;
let loop = (t - this._startTime) % duration; let loopCounting = Math.floor((t - this._startTime) / duration);
let r = loop / duration * PI2; if(loopCounting != this._loopCounting){
this._loopCounting = loopCounting;
if(this.onLoopEnd()){
return;
}
}
let pass = (t - this._startTime) % duration;
let r = pass / duration * PI2;
let params = waveParams || []; let params = waveParams || [];
let props = _waveMethod(...params, r); let props = _waveMethod(...params, r);
...@@ -104,7 +116,20 @@ export default class Wave extends ScillaComponent { ...@@ -104,7 +116,20 @@ export default class Wave extends ScillaComponent {
} }
} }
private onLoopEnd(){
if (this.loop < 0) {
this.onLoopComplete.invoke();
} else if (this._loopCounting < this.loop) {
this.onLoopComplete.invoke();
} else {
this._playing = false;
this.onComplete.invoke();
return true;
}
}
play() { play() {
this._loopCounting = -1;
this._playing = true; this._playing = true;
this._startTime = 0; this._startTime = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment