Setting the ground sprite for the hero with different types of grass and water

Started by alexgleason, December 31, 2018, 07:07:34 PM

Previous topic - Next topic
My game has several different types of grass and water. Is there a way to set ground1 and ground2 to a different sprite when entering a different area?

I'd also be curious if it's possible to set the direction of the ground based on the hero's direction. eg, when the hero faces left ground2 looks different.

Thanks!
RIP Aaron Swartz

Quote from: alexgleason on December 31, 2018, 07:07:34 PM
Is there a way to set ground1 and ground2 to a different sprite when entering a different area?

I don't know if it is possible to change the sprite itself, but it should be possible to change the animation of the sprite at least to give it a different appearance. You'll probably have to use sprite:on_animation_changed(animation) to manually change it every time it updates, though.

Quote from: alexgleason on December 31, 2018, 07:07:34 PM
I'd also be curious if it's possible to set the direction of the ground based on the hero's direction. eg, when the hero faces left ground2 looks different.

I'd imagine that the following would work:
Code (lua) Select

function hero:get_sprite"tunic":on_direction_changed(animation, direction)
  local ground_sprite = hero:get_sprite"ground"
  if ground_sprite then
    ground_sprite:set_direction(direction)
  end
end

In this is a similar topic "Multiple ground sprites?" , we learn that there should be a new feature in version 1.6, but in fact I'm not sure it exists.  :'(

You can do it even more easily in 1.6, now that you can add any sprite to the hero.