Hy everyone.
I will try to explain my problem the best I can.
So I have a side scroller game like Flappy Bird, with some type of enemies. Everything is done using JS.
I have one enemy that I called Slime, that gives me one issue that none of the others do, this is the Slime:
So lets say every 1 second the enemy picks one position to go. When the Slime goes to the right it does a hop that moves twice as far as it is suppose to and if it hops to the left it moves half of what was suppose to travel. So my first guess is since this is a side scroller and I'm moving everything on the screen besides the player (including this enemy) the issue is that I need to take into account the travel Speed of the objects movement. And I have done that and the issue keeps happening. All the enemies work fine and all of them use the same class Enemy so it's the same code for all of them.
After some research on this I found that if I change the Moving animation polygon to stay always the same, so no changes on frames. Puff the issue is gone. And this enemy is the only one that has a different movement polygon, the others don't change much the polygon while moving.
However I feel this is more a symptom of something I'm doing wrong. Does anyone know why changing the polygon during an animation affects how a object moves ?
Here is the code I use to move the enmies:
if (this._direction == 1 && !this._hasObstacleRight && !this._nearRightEdge) {
this.i.setAnimation('Run');
this.i.behaviors.Platform.simulateControl('right');
this.Mirror(true);
if (this.CanHop) this._isHopping = true;
} else if (this._direction == -1 && !this._hasObstacleLeft && !this._nearLeftEdge) {
this.i.setAnimation('Run');
this.i.behaviors.Platform.simulateControl('left');
this.Mirror(false);
if (this.CanHop) this._isHopping = true;
} else {
this.i.setAnimation('Idle');
if (this.CanHop) this._isHopping = false;
}