Mole-chan wrote:
I created a sprite state,
Code:
$cadfaelSprite.AddStateSprite("damage", "cad_battle damage")
and applied the DamageState extra to the battle. However, it remains in the default state, even after damage is taken.
The problem you're facing is that immediately after the damage state is set, the code sets the state back to 'default'. It's intended to be a short animation which plays as the character takes damage, not a permanent state (for that, you're actually best off replacing the fighter's sprite with a new one, which obviously could be a bit of a hassle... I'll add it to my To-Do list to add some sort of sprite-changing mechanism, but it's going to be fairly low-priority, I'm afraid.
Anyway, when a sprite state change occurs, the engine obviously starts out with the start-state displayed, it looks for a transition from start-state to target-state and if it finds one, plays it, waits for it to finish (duration defined when the transition is added) and then displays the target state. The DamageState extra simply causes the fighter's sprite to transition to 'damage' and back to 'default' whenever it takes damage, so the engine will do something like:
<damage occurs>
- State changes to 'damage'
- Look for a transition from "default" (or whatever state the fighter is presently in) to "damage"
- If it finds one, it replaces the fighter's sprite with the Displayable set for that transition
- Then waits the duration defined for that transition
- Next, the "damage" sprite is displayed
- Immediately after, the state changes to "default"
- Look for a transition from "damage" to "default"
- If it finds one, it replaces the fighter's sprite with the Displayable set for that transition
- Then waits the duration defined for that transition
- The "default" sprite is displayed.
So if you want to include a short animation which plays as the character takes damage (e.g. the so-called 'pain frames' that a lot of 2D games have) you'll actually need to add a state
transition, which is a short animation which plays when moving from one state to another. It's intended originally for things like animations rotating the character from one facing to another, if that helps conceptually?
Code:
$ myFighterSprite.AddStateTransition("damage", "default", "myFighter damage", 0.5)
This will play an animation called "myFighter damage" for 0.5 seconds whenever the state transitions from "damage" to "default". (You may think it's weird that it's damage->default and not the other way around, but it's safest like that - we don't know what state the fighter is in before they take damage, but we know that they definitely go to default
after taking damage, and it'll happen so fast that the player won't notice the difference anyway.)
Mole-chan wrote:
Thanks in advance, and sorry for the trouble.
You're welcome - and it's no trouble!