Files
sudoku/src/views/common/UISequenceAnimation.ts

61 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-06-10 18:24:50 +08:00
const { regClass, property } = Laya
2025-06-09 20:00:33 +08:00
@regClass()
export class UISequenceAnimation extends Laya.Script {
2025-06-10 18:24:50 +08:00
declare owner: Laya.Image
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
@property(String)
public prefix: string
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
@property(Number)
public beginIndex: number = 0
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
@property(Number)
public endIndex: number
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
@property(Boolean)
public playOnAwake: boolean = true
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
@property(Boolean)
public loop: boolean = false
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
private running: boolean = false
private currentIndex: number = 0
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
onAwake(): void {
if (this.playOnAwake) {
this.running = true
} else {
this.running = false
2025-06-09 20:00:33 +08:00
}
2025-06-10 18:24:50 +08:00
this.currentIndex = this.beginIndex
}
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
onLateUpdate(): void {
if (this.running) {
if (this.currentIndex > this.endIndex) {
this.currentIndex = this.beginIndex
if (this.loop === false) {
this.running = false
this.owner.visible = false
2025-06-09 20:00:33 +08:00
}
2025-06-10 18:24:50 +08:00
}
let endStr = this.currentIndex.toString()
if (this.currentIndex < 10) {
endStr = `00${this.currentIndex}`
} else if (this.currentIndex < 100) {
endStr = `0${this.currentIndex}`
}
const path = `${this.prefix + endStr}.png`
// ResourceManager.getInstance().loadTexture(path, this.image)
this.owner.skin = path
this.currentIndex++
2025-06-09 20:00:33 +08:00
}
2025-06-10 18:24:50 +08:00
}
2025-06-09 20:00:33 +08:00
2025-06-10 18:24:50 +08:00
onSetRunning(running: boolean): void {
this.running = running
}
}