https://love2d.org/imgmirrur/48kJWdy.mp4
Basically the draw code I'm using for my left facing animation works exactly how it should but when I draw the animation for the right side it looks..off. My player's head doesn't seem to move with the body even though it's all connected in the png file, there's also a weird offset happening when the run animation is playing but only for the non-mirrored(right facing) animation.
Code: Select all
function player.draw()
local playerScaling = 2
for i,v in ipairs(player) do
love.graphics.setColor(1, 1, 1)
--width is used here to calculate offset when mirroring texture
local plrWidth = v.animationTable[math.floor(v.current_frame)]:getWidth() * playerScaling
local plrHeight = v.animationTable[math.floor(v.current_frame)]:getHeight() * playerScaling
v.width, v.height = plrWidth, plrHeight
--flips player's texture when switching directions
if v.dir == "right" then
love.graphics.draw(v.animationTable[math.floor(v.current_frame)], v.x, v.y, 0, playerScaling, playerScaling, 0, 0)
elseif v.dir == "left" then
love.graphics.draw(v.animationTable[math.floor(v.current_frame)], v.x, v.y, 0, -playerScaling, playerScaling, plrWidth / playerScaling, 0)
end
end
end
Code: Select all
player_run = {}
player_run[1] = love.graphics.newImage("resources/textures/player/run/1.png")
player_run[2] = love.graphics.newImage("resources/textures/player/run/2.png")
player_run[3] = love.graphics.newImage("resources/textures/player/run/3.png")
player_run[4] = love.graphics.newImage("resources/textures/player/run/4.png")
player_run[5] = love.graphics.newImage("resources/textures/player/run/5.png")
player_run[6] = love.graphics.newImage("resources/textures/player/run/6.png")
player_run[7] = love.graphics.newImage("resources/textures/player/run/7.png")
player_run[8] = love.graphics.newImage("resources/textures/player/run/8.png")