Files
esengine/source/src/Utils/SubpixelNumber.ts
2020-08-12 12:16:35 +08:00

27 lines
916 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module es {
/**
* 管理数值的简单助手类。它存储值直到累计的总数大于1。一旦超过1该值将在调用update时添加到amount中。
*/
export class SubpixelNumber {
public remainder: number;
/**
* 以amount递增余数将值截断为int存储新的余数并将amount设置为当前值。
* @param amount
*/
public update(amount: number){
this.remainder += amount;
let motion = Math.trunc(this.remainder);
this.remainder -= motion;
return motion;
}
/**
* 将余数重置为0。当一个物体与一个不可移动的物体碰撞时有用。
* 在这种情况下,您将希望将亚像素余数归零,因为它是空的和无效的碰撞。
*/
public reset(){
this.remainder = 0;
}
}
}