• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 14804036802

02 May 2025 09:58PM UTC coverage: 5.927% (-83.4%) from 89.28%
14804036802

Pull #3404

github

web-flow
Merge 5c103d7f8 into 0f2ccaeb2
Pull Request #3404: feat: added Graph module to Math

234 of 8383 branches covered (2.79%)

229 of 246 new or added lines in 1 file covered. (93.09%)

13145 existing lines in 208 files now uncovered.

934 of 15759 relevant lines covered (5.93%)

4.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/engine/Graphics/TiledSprite.ts
1
import { Future } from '../Util/Future';
2
import { ImageFiltering } from './Filtering';
3
import { GraphicOptions } from './Graphic';
4
import { ImageSource, ImageWrapConfiguration } from './ImageSource';
5
import { SourceView, Sprite } from './Sprite';
6
import { ImageWrapping } from './Wrapping';
7

8
export interface TiledSpriteOptions {
9
  image: ImageSource;
10
  /**
11
   * Source view into the {@link ImageSource image}
12
   */
13
  sourceView?: SourceView;
14
  /**
15
   * Optionally override {@link ImageFiltering filtering}
16
   */
17
  filtering?: ImageFiltering;
18
  /**
19
   * Optionally override {@link ImageWrapping wrapping} , default wrapping is Repeat for TiledSprite
20
   */
21
  wrapping?: ImageWrapConfiguration | ImageWrapping;
22
  /**
23
   * Total width in pixels for the tiling to take place over
24
   */
25
  width: number;
26
  /**
27
   * Total height in pixels for the tiling to take place over
28
   */
29
  height: number;
30
}
31

32
export class TiledSprite extends Sprite {
UNCOV
33
  private _ready = new Future<void>();
×
UNCOV
34
  public ready = this._ready.promise;
×
35
  private _options: TiledSpriteOptions & GraphicOptions;
36
  constructor(options: TiledSpriteOptions & GraphicOptions) {
UNCOV
37
    super({
×
38
      image: options.image,
39
      sourceView: options.sourceView,
40
      destSize: { width: options.width, height: options.height },
41
      flipHorizontal: options.flipHorizontal,
42
      flipVertical: options.flipVertical,
43
      rotation: options.rotation,
44
      scale: options.scale,
45
      opacity: options.opacity,
46
      tint: options.tint,
47
      origin: options.origin
48
    });
UNCOV
49
    this._options = options;
×
50

UNCOV
51
    if (this.image.isLoaded()) {
×
UNCOV
52
      this._applyTiling();
×
53
    } else {
UNCOV
54
      this.image.ready.then(() => this._applyTiling());
×
55
    }
56
  }
57

58
  public static fromSprite(sprite: Sprite, options?: Partial<Omit<TiledSpriteOptions & GraphicOptions, 'image'>>): TiledSprite {
UNCOV
59
    return new TiledSprite({
×
60
      sourceView: { ...sprite.sourceView },
61
      width: sprite.width,
62
      height: sprite.height,
63
      ...options,
64
      image: sprite.image
65
    });
66
  }
67

68
  private _applyTiling() {
UNCOV
69
    const { width, height, filtering, wrapping } = { ...this._options };
×
UNCOV
70
    const spriteCanvas = document.createElement('canvas')!;
×
UNCOV
71
    spriteCanvas.width = this.sourceView.width;
×
UNCOV
72
    spriteCanvas.height = this.sourceView.height;
×
UNCOV
73
    const spriteCtx = spriteCanvas.getContext('2d')!;
×
74
    // prettier-ignore
UNCOV
75
    spriteCtx.drawImage(
×
76
        this.image.image,
77
        this.sourceView.x, this.sourceView.y,
78
        this.sourceView.width, this.sourceView.height,
79
        0, 0,
80
        this.sourceView.width, this.sourceView.height);
81

82
    // prettier-ignore
UNCOV
83
    const tiledImageSource = ImageSource.fromHtmlCanvasElement(spriteCanvas, {
×
84
        wrapping: wrapping ?? ImageWrapping.Repeat,
×
85
        filtering
86
      });
UNCOV
87
    if (width) {
×
UNCOV
88
      this.destSize.width = width;
×
UNCOV
89
      this.sourceView.width = width;
×
90
    }
UNCOV
91
    if (height) {
×
UNCOV
92
      this.destSize.height = height;
×
UNCOV
93
      this.sourceView.height = height;
×
94
    }
UNCOV
95
    this.sourceView.x = 0;
×
UNCOV
96
    this.sourceView.y = 0;
×
UNCOV
97
    this.image = tiledImageSource;
×
98
    // this._ready.resolve();
UNCOV
99
    this.image.ready.then(() => this._ready.resolve());
×
100
  }
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc