1
0
Fork 0
spacetac/src/ui/common/UIBatch.ts
2018-07-13 16:15:01 +02:00

51 lines
1.2 KiB
TypeScript

module TK.SpaceTac.UI {
export interface UIBatchOptions {
// Image key
image: string
// Initial location
x?: number
y?: number
}
/**
* UI component to display a batch of the same image repeated a great number of times
*/
export class UIBatch {
private internal: Phaser.GameObjects.Blitter
constructor(view: BaseView, options: UIBatchOptions) {
let info = view.getImageInfo(options.image);
this.internal = view.add.blitter(options.x || 0, options.y || 0, info.key, info.frame);
}
/**
* Add to a container
*/
addToContainer(container: UIContainer): void {
container.add(this.internal);
}
/**
* Set the location of the whole batch
*/
setPosition(x: number, y: number): void {
this.internal.setPosition(x, y);
}
/**
* Clear the batch of all items
*/
clear(): void {
this.internal.clear();
}
/**
* Add an item to the batch
*/
add(x: number, y: number): void {
this.internal.create(x, y);
}
}
}