import * as PIXI from './../com/pixi.min'; import Point from './../math/Point'; class Image extends PIXI.Sprite { texture: any; scale: any; W: number; x: number; y: number; H: number; tint: any; alpha: number; anchor: any; iscale: Point; pivot: Point; constructor(name, options: any = {}) { super(PIXI.Texture.fromFrame(name)); if (options.trim) { this.W = this.texture.trim.width; this.H = this.texture.trim.height; } else { this.W = this.texture.width; this.H = this.texture.height; } if (options.s) { this.scale.x = this.scale.y = options.s; } if (options.c) { this.tint = options.c; } if (options.a) { this.alpha = options.a; } } move(x, y) { this.x = x; this.y = y; } rescale(scale) { this.scale.x = this.scale.y = scale; } recenter(pivot = null) { if (pivot) { this.pivot.x = this.W * pivot.x; this.pivot.y = this.H * pivot.y; } else { this.pivot.x = this.W / 2; this.pivot.y = this.H / 2; } } static Get(name, opts: object = {}) { let options: any = Object.assign({id: 0}, opts); let textureName = name + String(options.id).padStart(4, '0'); let image: Image = new Image(textureName, options); if (options.a) { image.anchor = new Point(options.a, options.a); } if (options.s) { image.scale = new Point(options.s, options.s); image.iscale = new Point(options.s, options.s); } return image; } } export default Image;