But now the players walk right animation just appears and it now doesn't move with the 'a' and 'd; keys
Code: Select all
assets = require('cargo').init('assets')
anim8 = require 'anim8'
platform = {}
player = {}
player.animations = {}
player.grids = {}
player.width = 32
player.height = 32
player. isMoving = false
player.grids.walk = anim8.newGrid(player.width, player.height, assets.images.player:getWidth(), assets.images.player:getHeight())
player.animations.walkRight = anim8.newAnimation(player.grids.walk('1-2', 1), 0.15)
player.animations.walkLeft = anim8.newAnimation(player.grids.walk('1-2', 2), 0.15)
player.anim = player.animations.walkLeft
function love.load()
love.window.setMode(1280, 720, {resizable=true, vsync=true, minwidth=8, minheight=8})
platform.width = love.graphics.getWidth()
platform.height = love.graphics.getHeight()
platform.x = 0
platform.y = 0
player.x = love.graphics.getWidth() / 2
player.y = love.graphics.getHeight() - 100
player.speed = 200
end
function love.update(dt)
player.animations.walkRight:update(dt)
player.animations.walkLeft:update(dt)
end
if love.keyboard.isDown("d") then
player.x = player.x + (player.speed * dt)
player.anim = player.animations.walkRight
player.anim:update(dt)
elseif love.keyboard.isDown("a") then
player.x = player.x - (player.speed * dt)
player.anim = player.animations.walkLeft
player.anim:update(dt)
end
function love.draw()
love.graphics.setBackgroundColor(172/255, 194/255, 217/255)
love.graphics.draw(assets.images.ground, 0, 652)
player.anim:draw(assets.images.player, player.x, player.y)
local font = love.graphics.setNewFont(10)
end