kxcrl / foundryvtt-retro

MIT License
0 stars 0 forks source link

Add sprite animations across the X axis #4

Closed kxcrl closed 10 months ago

kxcrl commented 10 months ago

Tile every sprite at its current Y position across the X axis to create an animation.

const frameCount = 0;

function animateSprites(sceneSprites) {
  sceneSprites.forEach((sprite) {
    if (spriteSheetWidth == 100px) {
      return;
    }

    if (atEdgeOfSpriteSheet(sprite)) {
      sprite.tilePosition.x = 0;
    } else {
      sprite.tilePosition.x += 100;
    }
  })
}

canvas.app.ticker.add(() => {
  if (frameCount % FRAME_RATE == 0) {
    animateSprites(sceneSprites);
  }
})