feat: handle single animation case
hypergryph why
This commit is contained in:
@@ -45,6 +45,8 @@ export default class Player {
|
|||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
const _this = this
|
const _this = this
|
||||||
|
const hasOtherAnimation =
|
||||||
|
this.#animationList.filter((item) => item === 'Idle').length > 0
|
||||||
const playerConfig = {
|
const playerConfig = {
|
||||||
atlasUrl: `${import.meta.env.BASE_URL}${buildConfig.default_assets_dir}${buildConfig.filename}.atlas`,
|
atlasUrl: `${import.meta.env.BASE_URL}${buildConfig.default_assets_dir}${buildConfig.filename}.atlas`,
|
||||||
premultipliedAlpha: true,
|
premultipliedAlpha: true,
|
||||||
@@ -87,6 +89,7 @@ export default class Player {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
complete: () => {
|
complete: () => {
|
||||||
|
if (!hasOtherAnimation) return
|
||||||
if (
|
if (
|
||||||
performance.now() - _this.#resetTime >= 8 * 1000 &&
|
performance.now() - _this.#resetTime >= 8 * 1000 &&
|
||||||
Math.random() < 0.3
|
Math.random() < 0.3
|
||||||
@@ -108,6 +111,13 @@ export default class Player {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
widget.canvas.onclick = function () {
|
widget.canvas.onclick = function () {
|
||||||
|
if (!hasOtherAnimation) return
|
||||||
|
if (
|
||||||
|
_this.#animationList.filter((item) => item === 'Idle')
|
||||||
|
.length === 0
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (_this.#isPlayingInteract) {
|
if (_this.#isPlayingInteract) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -191,7 +201,11 @@ export default class Player {
|
|||||||
const animationList = this.#animationList.filter((animation) =>
|
const animationList = this.#animationList.filter((animation) =>
|
||||||
animation.startsWith(name)
|
animation.startsWith(name)
|
||||||
)
|
)
|
||||||
return animationList[Math.floor(Math.random() * animationList.length)]
|
if (animationList.length > 0)
|
||||||
|
return animationList[
|
||||||
|
Math.floor(Math.random() * animationList.length)
|
||||||
|
]
|
||||||
|
else return 'Idle'
|
||||||
}
|
}
|
||||||
|
|
||||||
get usePadding() {
|
get usePadding() {
|
||||||
|
|||||||
Reference in New Issue
Block a user