Page 1 of 1

Anim8 Walking Animation using keys returning nil

Posted: Mon Oct 30, 2017 3:27 am
by peachyb
I'm trying to create a walking animation as the player walks using keys with anim8.
My code is as follows

Code: Select all

local anim8 = require 'anim8'

local spritesheet, animation

function love.load()
  spritesheet = love.graphics.newImage('paulaa.png')
  local g = anim8.newGrid(32, 48, spritesheet:getWidth(), spritesheet:getHeight())
animations = {
  left = anim8.newAnimation(g(1,4, 2,4, 3,4, 4,4), 0.1, onLoop),
  right = anim8.newAnimation(g(1,6, 2,6, 3,6, 4,6), 0.1, onLoop)
  }

current_animation = animations.left

end

function love.update(dt)
  if love.keyboard.isDown('a') then
    current_animation = animations.left:update(dt)
  end
end


function love.draw()
  current_animation:draw(spritesheet, 100, 200)
end

When the current_animation is changed to animations.left and the key being pressed code is removed, the animation works perfectly.
I don't understand why my code is returning nil when 'a' is pressed and why the sprite is still from the start of the program.

Re: Anim8 Walking Animation using keys returning nil

Posted: Mon Oct 30, 2017 12:46 pm
by Azhukar

Code: Select all

function love.update(dt)
	if love.keyboard.isDown('a') then
		current_animation = animations.left
		current_animation:update(dt)
	end
end
Read https://github.com/kikito/anim8

Re: Anim8 Walking Animation using keys returning nil

Posted: Mon Oct 30, 2017 9:48 pm
by peachyb
Azhukar wrote: Mon Oct 30, 2017 12:46 pm

Code: Select all

function love.update(dt)
	if love.keyboard.isDown('a') then
		current_animation = animations.left
		current_animation:update(dt)
	end
end
Read https://github.com/kikito/anim8
Thank you so much!! I have read that a few times over but I must've missed it.