Solarus-Games English Forum

Solarus => Bugs & Feature requests => Topic started by: Satoh on January 07, 2015, 04:33:03 AM

Title: Sword animation speed bug
Post by: Satoh 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?

Title: Re: Sword animation speed bug
Post by: Christopho 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.
Title: Re: Sword animation speed bug
Post by: Satoh 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?
Title: Re: Sword animation speed bug
Post by: Christopho 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() (http://www.solarus-games.org/doc/latest/lua_api_hero.html#lua_api_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 :)