Help adding animations

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Red Pig
Prole
Posts: 3
Joined: Wed Jan 08, 2020 10:00 am

Help adding animations

Post by Red Pig »

So I was trying to add animations using anim8
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
User avatar
CogentInvalid
Prole
Posts: 27
Joined: Sat Dec 14, 2013 12:15 am

Re: Help adding animations

Post by CogentInvalid »

You're ending love.update early.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 48 guests