this.targetXTimer = setTimeout(() => {
// calculate what the new x should be
const newX = dir === 1 // right
? this.x + (difference / this.inputCooldown)
: this.x - (difference / this.inputCooldown);
// handle collision
const collision = this.map.getCollision(newX, this.y);
if (collision) {
this.targetX = this.x;
difference = 0;
} else {
this.x = newX;
}
this.afterEaseMovement();
// if we're not close enough to the target Y, keep moving
if (difference > 1) {
this.targetXTimerHandler(dir, this.map);
}
}, difference / this.inputCooldown);
The implementation on these movements has a potential for mini "bursts" of clearTimeout() / setTimeout() per character as the character eases in/out of their target positions.
I think this needs to be refactored for performance and portability. We should look at the characterBaseClass draw() method as a candidate for calculating and update the character's position.
Character animation/easing from position to position relies on window.setTimeout to calculate character positions.
For NPC movements:
and for actual player movement:
The implementation on these movements has a potential for mini "bursts" of clearTimeout() / setTimeout() per character as the character eases in/out of their target positions.
I think this needs to be refactored for performance and portability. We should look at the characterBaseClass draw() method as a candidate for calculating and update the character's position.