How can I create sprite animations in a "grid-based" game in love2d?

I'm creating a pokemon game from 0 and I want to create the character movement style it has.

The squares of the map tilesets are 32x32, and those of the character 32x48. Therefore, to move it you need to add to The X or Y of the character 32 pixels. So far easy, but the thing gets complicated when we want to animate the character's sprite. In this case we have Professor Oak. Your tileset shows us how you should have 4 frames for the 4 moves basic, Up, Down, Left and right.

Faced with this problem, I decided to program it in such a way that every 8 pixels of wasd movement, using love.keyboard.isDown, would show the corresponding frame of each of its movements. The problem comes to light. Each time one of those keys is pressed, it only makes the 8-Pixel move, and stays in the next frame. That is, to make the journey of an entire square, you have to press the same key 4 times.

The question is make the 8-Pixel Movement 4 times in a row, without the user being able to press any keys until the 32-pixel movement is completed, avoiding multiple errors of choosing the wrong frame, and preventing the non-caged movement.

I tried to do it with loops for, but it doesn't draw well in function love.draw(), logical thing the truth.

I pass the entire code by one drive: https://1drv.ms/f/s! AvRWkdEmuSbYg0UOdQN9P2CBcIuS

I hope let there be some love function I can use to do this optimally. If it doesn't work because of the way it's programmed, I'm open to modifications.

 1
Author: Mariano, 2016-09-05

1 answers

2 years ago from the question but good... What I do is simply force that every time you press a key to move, the sprite does the four animations you have. This is the part of the code you have to change:

function muevePj(dt)
elapsed = elapsed + dt
    if elapsed > 0.1 then
        elapsed = elapsed - 0.1

        if love.keyboard.isDown("down") then
            down = true
        end
        if down == true then
            if currentFrame == 4 then
                currentFrame = 1
                down = false           --Hasta que no pasa por todas 
                                       --las fases, down no vuelve a false
            elseif currentFrame < 4 then

                currentFrame = currentFrame + 1
            end
            initPosY = initPosY + 8
        end

    end

End

 0
Author: Guille2025, 2019-04-01 08:56:21