Use origin again; add loop bool

This commit is contained in:
Ketchetwahmeegwun T. Southall 2022-01-30 09:16:41 -08:00
parent 5d7f940d20
commit dcb7b2abaf

View File

@ -22,6 +22,7 @@ export class SpriteInstance {
frameIndex: number = 0
frameCount: number = 0
animate: boolean = true
loop: boolean = true
elapsed: number = 0
constructor(ctor: string) {
@ -48,9 +49,18 @@ export class SpriteInstance {
this.subset = this.set.children[subsetKey]
//
if (this.subset.frames) {
if (this.frameIndex >= this.subset.frames.length) {
this.frameIndex = 0
}
this.frameCount = this.subset.frames.length
this.frame = this.subset.frames[this.frameIndex]
let s = new PIXI.Sprite(this.frame.texture)
if (this.frame.originX) {
s.pivot.x = this.frame.originX
}
if (this.frame.originY) {
s.pivot.y = this.frame.originY
}
this.container.addChild(s)
}
}
@ -62,6 +72,7 @@ export class SpriteInstance {
this.elapsed -= this.frame.time
this.frameIndex++
if (this.frameIndex >= this.frameCount) {
if (!this.loop) return
this.frameIndex = 0
}
this.setCtor(`${this.spriteKey}.${this.animationKey}.${this.setKey}.${this.subsetKey}.${this.frameIndex}`)