Anim8 Walking Animation using keys returning nil

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
peachyb
Prole
Posts: 4
Joined: Sun Oct 22, 2017 7:15 am

Anim8 Walking Animation using keys returning nil

Post by peachyb » Mon Oct 30, 2017 3:27 am

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.
Attachments
ani.love
(3.41 KiB) Downloaded 37 times

User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Anim8 Walking Animation using keys returning nil

Post by Azhukar » 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

peachyb
Prole
Posts: 4
Joined: Sun Oct 22, 2017 7:15 am

Re: Anim8 Walking Animation using keys returning nil

Post by peachyb » Mon Oct 30, 2017 9:48 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests