refactor: real time damage position
This commit is contained in:
parent
d8323ed9f3
commit
06066e5c43
|
@ -57,24 +57,24 @@ class Damage {
|
|||
tick(elapsed, stepSize) {
|
||||
this.elapsed += elapsed;
|
||||
this.step += elapsed;
|
||||
// offset
|
||||
let offsetX = 0, offsetY = 0;
|
||||
if (this.elapsed <= 0.5) {
|
||||
offsetX = easeOutQuad(this.elapsed, 0, this.offsetX, 0.5);
|
||||
offsetY = easeOutQuad(this.elapsed, 0, this.offsetY, 0.5);
|
||||
}
|
||||
else if (this.elapsed > 1.375) {
|
||||
offsetX = easeOutQuad(this.elapsed - 1.375, this.offsetX, -this.offsetX, 0.125);
|
||||
offsetY = easeOutQuad(this.elapsed - 1.375, this.offsetY, -this.offsetY, 0.125);
|
||||
}
|
||||
else {
|
||||
offsetX = this.offsetX;
|
||||
offsetY = this.offsetY;
|
||||
}
|
||||
this.element.style.setProperty('--offsetX', offsetX);
|
||||
this.element.style.setProperty('--offsetY', offsetY);
|
||||
if (this.step > stepSize) {
|
||||
this.step = this.step % stepSize;
|
||||
// offset
|
||||
let offsetX = 0, offsetY = 0;
|
||||
if (this.elapsed <= 0.5) {
|
||||
offsetX = easeOutQuad(this.elapsed, 0, this.offsetX, 0.5);
|
||||
offsetY = easeOutQuad(this.elapsed, 0, this.offsetY, 0.5);
|
||||
}
|
||||
else if (this.elapsed > 1.375) {
|
||||
offsetX = easeOutQuad(this.elapsed - 1.375, this.offsetX, -this.offsetX, 0.125);
|
||||
offsetY = easeOutQuad(this.elapsed - 1.375, this.offsetY, -this.offsetY, 0.125);
|
||||
}
|
||||
else {
|
||||
offsetX = this.offsetX;
|
||||
offsetY = this.offsetY;
|
||||
}
|
||||
this.element.style.setProperty('--offsetX', offsetX);
|
||||
this.element.style.setProperty('--offsetY', offsetY);
|
||||
// scale
|
||||
let scale = 0.35;
|
||||
if (this.elapsed <= 0.5) {
|
||||
|
@ -149,7 +149,7 @@ function Damages({scale}) {
|
|||
pool.current.push(new Damage());
|
||||
}
|
||||
}
|
||||
const stepSize = keys.length > 150 ? (keys.length / 500) * 0.25 : elapsed;
|
||||
const stepSize = keys.length > 150 ? (keys.length / 500) * 0.5 : elapsed;
|
||||
for (const key of keys) {
|
||||
const damage = damages.current[key];
|
||||
damage.tick(elapsed, stepSize);
|
||||
|
|
Loading…
Reference in New Issue
Block a user