Custom animation system not working, no reason why
Posted: Thu Jul 19, 2018 8:03 pm
So I'm trying to add animations to my project, and recently I've noticed a number of issues that seem to make no sense, however I'm only going to mention one here, because this one in particular has literally (as far as I know) no reason to occur. Basically, when I assign an animation to a variable, and use that as the player's animation, the animation is distorted, but when I just create a new animation, everything's fine.
Here's my code:
And this is the strange part. When I type this:
everything looks weird, but when I type this:
everything works. You'll notice that the animation used in the latter example is the exact same animation used in the former, so why are they yielding different results? Is this a known but (I'm new to Love2D). Any insight is appreciated!
Here's my code:
Code: Select all
function gamestate.loadimages()
gamestate.playerupanimatlas = love.graphics.newImage("Assets/Graphics/Player Animations/PlayerUpAnim.png")
gamestate.playerdownanimatlas = love.graphics.newImage("Assets/Graphics/Player Animations/PlayerDownAnim.png")
gamestate.playerleftanimatlas = love.graphics.newImage("Assets/Graphics/Player Animations/PlayerLeftAnim.png")
gamestate.playerrightanimatlas = love.graphics.newImage("Assets/Graphics/Player Animations/PlayerRightAnim.png")
gamestate.playerswingupanimatlas = love.graphics.newImage("Assets/Graphics/Player Animations/PlayerSwingDownAnim.png")
gamestate.playerswingdownanimatlas = love.graphics.newImage("Assets/Graphics/Player Animations/PlayerSwingDownAnim.png")
gamestate.playerswingleftanimatlas = love.graphics.newImage("Assets/Graphics/Player Animations/PlayerSwingDownAnim.png")
gamestate.playerswingrightanimatlas = love.graphics.newImage("Assets/Graphics/Player Animations/PlayerSwingDownAnim.png")
end
function gamestate.initanims()
gamestate.playerupanim = animation:new(gamestate.playerupanimatlas, 10, 2, 16, 32)
gamestate.playerdownanim = animation:new(gamestate.playerdownanimatlas, 10, 2, 16, 32)
gamestate.playerleftanim = animation:new(gamestate.playerleftanimatlas, 10, 2, 16, 32)
gamestate.playerrightanim = animation:new(gamestate.playerrightanimatlas, 10, 2, 16, 32)
gamestate.playeranims =
{
moveupanim = gamestate.playerupanim,
movedownanim = gamestate.playerdownanim,
moveleftanim = gamestate.playerleftanim,
moverightanim = gamestate.playerleftanim,
}
gamestate.playerswingupanim = animation:new(gamestate.playerswingupanimatlas, 30, 2, 16, 32)
gamestate.playerswingdownanim = animation:new(gamestate.playerswingdownanimatlas, 30, 2, 16, 32)
gamestate.playerswingleftanim = animation:new(gamestate.playerswingleftanimatlas, 30, 2, 16, 32)
gamestate.playerswingrightanim = animation:new(gamestate.playerswingrightanimatlas, 30, 2, 16, 32)
gamestate.playerswinganims =
{
swingupanim = gamestate.playerswingupanim,
swingdownanim = gamestate.playerswingdownanim,
swingleftanim = gamestate.playerswingleftanim,
swingrightanim = gamestate.playerswingrightanim,
}
end
Code: Select all
player.animations = gamestate.playeranims
player.currentanim = player.animations.moveupanim
Code: Select all
player.animations = gamestate.playeranims
player.currentanim = animation:new(gamestate.playerupanimatlas, 10, 2, 16, 32)