
I came out with a simple solution, one that at least works pretty fine for me.
Still, I have not tried it with other animations, just with normal walking/stopped animations but I guess it should work.
It uses 2 sprites, one with the normal directions, and another one with the additional 4 diagonal directions,
then I switch the sprites and assigned the directions as needed.
I had trouble because there was a feedback from the key events, some simple logic worked as a fix.
There should be a more elegant solution, but as I said it works nicely for me right now.
This goes inside the hero.lua file
local function initialize_hero_features(game)
local hero = game:get_hero()
hero:set_tunic_sprite_id("her/her-normal")
function hero:on_position_changed(x, y, layer)
-- Set diagonal movements
if (sol.input.is_key_pressed("right") and not sol.input.is_key_pressed("up") and not sol.input.is_key_pressed("down")) then
hero:set_tunic_sprite_id("her/her-normal")
end
if (sol.input.is_key_pressed("left") and not sol.input.is_key_pressed("up") and not sol.input.is_key_pressed("down")) then
hero:set_tunic_sprite_id("her/her-normal")
end
if (sol.input.is_key_pressed("up") and not sol.input.is_key_pressed("right") and not sol.input.is_key_pressed("left")) then
hero:set_tunic_sprite_id("her/her-normal")
end
if (sol.input.is_key_pressed("down") and not sol.input.is_key_pressed("right") and not sol.input.is_key_pressed("left")) then
hero:set_tunic_sprite_id("her/her-normal")
end
if (sol.input.is_key_pressed("left") and sol.input.is_key_pressed("up") ) then
hero:set_tunic_sprite_id("her/her-diagonal")
hero:set_direction(1)
end
if (sol.input.is_key_pressed("left") and sol.input.is_key_pressed("down") ) then
hero:set_tunic_sprite_id("her/her-diagonal")
hero:set_direction(2)
end
if (sol.input.is_key_pressed("right") and sol.input.is_key_pressed("up") ) then
hero:set_tunic_sprite_id("her/her-diagonal")
hero:set_direction(0)
end
if (sol.input.is_key_pressed("right") and sol.input.is_key_pressed("down") ) then
hero:set_tunic_sprite_id("her/her-diagonal")
hero:set_direction(3)
end
end
end