新增ninja adventure例子

This commit is contained in:
YHH
2020-08-23 22:09:22 +08:00
parent 6c1cfec928
commit 7345a17d24
26 changed files with 400 additions and 27 deletions

View File

@@ -0,0 +1,32 @@
module es {
/**
* 它存储值直到累计的总数大于1。一旦超过1该值将在调用update时添加到amount中
* 一般用法如下:
*
* let deltaMove = this.velocity * es.Time.deltaTime;
* deltaMove.x = this._x.update(deltaMove.x);
* deltaMove.y = this._y.update(deltaMove.y);
*/
export class SubpixelFloat {
public remainder: number = 0;
/**
* 以amount递增余数将值截断存储新的余数并将amount设置为当前值
* @param amount
*/
public update(amount: number){
this.remainder += amount;
let motion = Math.trunc(this.remainder);
this.remainder -= motion;
amount = motion;
return amount;
}
/**
* 将余数重置为0
*/
public reset(){
this.remainder = 0;
}
}
}

View File

@@ -0,0 +1,23 @@
module es {
export class SubpixelVector2 {
public _x: SubpixelFloat = new SubpixelFloat();
public _y: SubpixelFloat = new SubpixelFloat();
/**
* 以数量递增s/y余数将值截断为整数存储新的余数并将amount设置为当前值
* @param amount
*/
public update(amount: Vector2) {
amount.x = this._x.update(amount.x);
amount.y = this._y.update(amount.y);
}
/**
* 将余数重置为0
*/
public reset(){
this._x.reset();
this._y.reset();
}
}
}