Solarus-Games English Forum

Solarus => Development => Topic started by: Starlock on October 08, 2016, 10:16:35 PM

Title: Stop hero animation outside collision
Post by: Starlock on October 08, 2016, 10:16:35 PM
I'm trying to make a collision test on a custom entity  that changes the hero animation while overlapping. Setting the animation works, but the animation persists outside of the entity until the hero stops moving. What do I do to fix this?

This is the chunk:

Code ( lua) Select
  entity:add_collision_test("overlapping", function()
    if entity:overlaps(hero) then
      hero:set_animation("spring")
    end
    return true
  end)
Title: Re: Stop hero animation outside collision
Post by: Christopho on October 08, 2016, 11:11:57 PM
You start an animation but you never stops it. So it only stops when another one is set, here by the engine when the hero stops moving.

What you can do is use a repetitive timer to check regularly if the entity is still overlapping the hero, and if not, stop the animation.
Title: Re: Stop hero animation outside collision
Post by: Starlock on October 09, 2016, 02:52:54 AM
It works now, but is there a way to prevent the hero from using items during the collision? If an item is used the hero just ends up freezing.
Title: Re: Stop hero animation outside collision
Post by: Christopho on October 09, 2016, 07:21:58 AM
Try hero:freeze()
Title: Re: Stop hero animation outside collision
Post by: Starlock on October 09, 2016, 05:37:26 PM
Won't that just make the hero unable to move? The hero should be able to move, the problem is that he stops moving when he attempts to use his sword. I'm thinking of using on_command_pressed but I'm not sure what to do to make the hero unable to do anything besides move.