kaplayjs / kaplay

🦖 A JavaScript/TypeScript Game Library that feels like a game, fun
https://kaplayjs.com
MIT License
506 stars 34 forks source link

feat: fallback animation for sprites #256

Open candycarmel opened 3 months ago

candycarmel commented 3 months ago

sort of related to a problem, more a helpful feature

constantly checking if the current animation is null before checking what the current animations name is is kind of tiresome

I'd like a fallback animation option for sprites

You should be able to provide the name of the fallback animation in the anims opt

I have a small code snippet in update that checks if the animation is null and then changes it to the fallback animation instead.

i dont think any other context should be needed

:)

mflerackers commented 2 months ago

You could use obj.getCurAnim()?.name, that way you don't need to test for null.