refactor: real time damage position

This commit is contained in:
cha0s 2024-08-05 13:33:32 -05:00
parent d8323ed9f3
commit 06066e5c43

View File

@ -57,8 +57,6 @@ class Damage {
tick(elapsed, stepSize) {
this.elapsed += elapsed;
this.step += elapsed;
if (this.step > stepSize) {
this.step = this.step % stepSize;
// offset
let offsetX = 0, offsetY = 0;
if (this.elapsed <= 0.5) {
@ -75,6 +73,8 @@ class Damage {
}
this.element.style.setProperty('--offsetX', offsetX);
this.element.style.setProperty('--offsetY', offsetY);
if (this.step > stepSize) {
this.step = this.step % stepSize;
// 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);