Page 1 of 1

Anim8 Issue: There is no frame for x=1, y=2

Posted: Sun Oct 22, 2017 7:28 am
by peachyb
I'm very inexperienced and I have little idea what I'm doing. I'm assuming I've made a simple mistake but I just can't find it :cry:

I'm using anim8 but I can't make it actually animate a walking motion, left to right using an earthbound sprite sheet. I've measured the dimensions of the sprite sheet (the sheet is 128x98, the individual frames are 32x48) so I don't know where I've screwed up.
The error I get is 'There is no frame for x=1, y=2'.

Code: Select all

local anim8 = require 'anim8'
local player

function love.load()
  local spritesheet = love.graphics.newImage('ANIMATION/paulaani.png');
  local g = anim8.newGrid(32, 48, 128, 98)

  player = {
    spritesheet = spritesheet,
    x = 200,
    y = 200,
    speed = 50,
    animations = {
      left = anim8.newAnimation('loop', g(1,1, 1,2, 1,3, 1,4), 1.0),
      right =  anim8.newAnimation('loop', g(2,1, 2,2, 2,3, 2,4), 1.0)
    }
  }
  player.animation = love.graphics.newImage('ANIMATION/paula.png') -- player starts looking down
end

function love.update(dt)
  if love.keyboard.isDown("w") then
    player.y = player.y - player.speed * dt

  elseif love.keyboard.isDown("s") then
    player.y = player.y + player.speed * dt

  elseif love.keyboard.isDown("a") and player.x > 0 then
    player.x = player.x - player.speed * dt
    player.animation = player.animations.left
  elseif love.keyboard.isDown("d") and player.x < 10000 then
    player.x = player.x + player.speed * dt
    player.animation = player.animations.right
  end
  player.animation:update(dt)
end
I've also attached the .love file.

Thanks!

Re: Anim8 Issue: There is no frame for x=1, y=2

Posted: Sun Oct 22, 2017 9:13 pm
by mr_happy
Hello

I'm afraid I know nothing about anim8 and haven't looked at your love file but but I'm guessing your spritesheet has two rows of four frames? A few things to consider, which may or may not be relevant:

a) 2 x 48 = 96, not 98
b) It's usually better to separate processing of input from update() logic
c) Do you really want to allow player.x to reach almost 10,000?
d) If you're inexperienced it's probably better not to use an external library as that's just another place for errors or misunderstanding to creep in... why not just used love2d to get a basic animation working first of all?

Re: Anim8 Issue: There is no frame for x=1, y=2

Posted: Mon Oct 23, 2017 1:40 pm
by Azhukar
Here is a guide on the library you're using, which you didn't read: https://github.com/kikito/anim8

The proper way to create your animation according to the above is this:

Code: Select all

left = anim8.newAnimation(g(1,1, 2,1, 3,1, 4,1), 1.0),
right =  anim8.newAnimation(g(1,2, 2,2, 3,2, 4,2), 1.0)
In your code you seem to have confused the x and y axis and even switched them around arbitrarily. You're also incorrectly updating the animation, but all that is explained in the guide above.

Re: Anim8 Issue: There is no frame for x=1, y=2

Posted: Mon Oct 23, 2017 10:43 pm
by peachyb
Thank you for the help!!
I decided to ditch my code and use the example on github, as well as changing my sprite sheet.
The issue was with the dimensions of my sprite sheet being wrong as well as some other errors I fixed up.