Use origin again; add loop bool
This commit is contained in:
parent
5d7f940d20
commit
dcb7b2abaf
|
@ -22,6 +22,7 @@ export class SpriteInstance {
|
||||||
frameIndex: number = 0
|
frameIndex: number = 0
|
||||||
frameCount: number = 0
|
frameCount: number = 0
|
||||||
animate: boolean = true
|
animate: boolean = true
|
||||||
|
loop: boolean = true
|
||||||
elapsed: number = 0
|
elapsed: number = 0
|
||||||
|
|
||||||
constructor(ctor: string) {
|
constructor(ctor: string) {
|
||||||
|
@ -48,9 +49,18 @@ export class SpriteInstance {
|
||||||
this.subset = this.set.children[subsetKey]
|
this.subset = this.set.children[subsetKey]
|
||||||
//
|
//
|
||||||
if (this.subset.frames) {
|
if (this.subset.frames) {
|
||||||
|
if (this.frameIndex >= this.subset.frames.length) {
|
||||||
|
this.frameIndex = 0
|
||||||
|
}
|
||||||
this.frameCount = this.subset.frames.length
|
this.frameCount = this.subset.frames.length
|
||||||
this.frame = this.subset.frames[this.frameIndex]
|
this.frame = this.subset.frames[this.frameIndex]
|
||||||
let s = new PIXI.Sprite(this.frame.texture)
|
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)
|
this.container.addChild(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +72,7 @@ export class SpriteInstance {
|
||||||
this.elapsed -= this.frame.time
|
this.elapsed -= this.frame.time
|
||||||
this.frameIndex++
|
this.frameIndex++
|
||||||
if (this.frameIndex >= this.frameCount) {
|
if (this.frameIndex >= this.frameCount) {
|
||||||
|
if (!this.loop) return
|
||||||
this.frameIndex = 0
|
this.frameIndex = 0
|
||||||
}
|
}
|
||||||
this.setCtor(`${this.spriteKey}.${this.animationKey}.${this.setKey}.${this.subsetKey}.${this.frameIndex}`)
|
this.setCtor(`${this.spriteKey}.${this.animationKey}.${this.setKey}.${this.subsetKey}.${this.frameIndex}`)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user