Author Topic: Sword animation speed bug  (Read 1441 times)

Satoh

  • Newbie
  • *
  • Posts: 47
    • View Profile
Sword animation speed bug
« on: January 07, 2015, 04:33:03 am »
I'm terrible at introductions so I'll jump right into what I wanted, and what I did.

I was trying to make the sword swing faster, so the character could move around without being rooted to the ground for so long. (something more like Zelda GBC games)

After I discovered the sword attack is not exposed to editing in Lua... at least as far as I could find, I decided to change the animation speed instead.
This is where the bug happens.

No mater what speed the sword animation is set to, whether its Animation Delay=1 or 500, the sword swinging does not change at all.

I thought the settings might not be getting saved, so...
I tested this by changing the sprite image for the sword. The sword in game looks different, but the swing is the same speed.

How can I modify the sword behavior?
Should I create a new item entirely for it?

Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1177
    • View Profile
Re: Sword animation speed bug
« Reply #1 on: January 07, 2015, 11:08:08 am »
There are several sprites involved when the hero is swinging his sword: the sword sprite, but also the tunic sprite and the shield sprite. If you change the animation speed of one of them, or if you remove some frames, then you should also do the same change in the other two sprites.

Satoh

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Sword animation speed bug
« Reply #2 on: January 07, 2015, 09:08:54 pm »
The tunic... the main body... that makes sense. It seems that changing that one, by itself, changes the swinging animation. I hadn't considered it since it was sort of like a different item.

Is there a way to change the animation speed at run-time, like through Lua?
Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1177
    • View Profile
Re: Sword animation speed bug
« Reply #3 on: January 07, 2015, 09:34:55 pm »
Exactly, the tunic sprite is the master one. Its state determines the end of the sword sequence. Actually, the sword and shield one are even synchronized to the tunic one.

If you want to change the animation speed at runtime, a way to do that is to change the animation with hero:set_animation(), setting another animation that has the same frames but a different speed.

The sprite API would give more control, but you don't have direct access to the sprites objects of the hero like you can with enemies or custom entities (well… except with very dirty metatable tricks). But you can do a few things through the hero functions like hero:set_animation(). The reason why the sprites of the hero are not directly exposed to Lua is because they belong to the engine only. Maybe this will change one day :)
« Last Edit: January 07, 2015, 09:37:04 pm by Christopho »