PixiJS Update loop & delta

2.7k Views Asked by At

When using PixiJS, I noticed that sprites that I move in a straight line at constant speed sometimes "jump" seemingly randomly - usually falling slightly behind their expected position. This is especially noticeable with fast-moving projectiles.

I assume this may have to do with my update loop, and especially how I use Pixi's delta.

My way of adding my update loop to Pixi's ticker:

pixiApp.ticker.add(update);

My update loop using Pixi's delta:

update(delta) {
    entity.x += direction * speed * delta;
    animatedSprite.x = entity.x;
}

I assume what is happening is whenever delta drops, my entity moves a shorter distance that frame, leading to the "jumps" and "falling behind" I see in the entity's movement.

I have also read that - unlike other engines - in PixiJS, delta is not actually "the time elapsed since the last frame in ms", but rather something else that's not in ms and that I'm not sure I fully understand.

Is there a way around this? I read something about rolling your own update loop, and Pixi's ticker potentially only being meant for updating the sprite animations themselves, but not for movement and other gameplay mechanics in the way I do it here?

0

There are 0 best solutions below