kikito / anim8

An animation library for LÖVE
MIT License
730 stars 88 forks source link

There is no frame for x=value, y=value #25

Closed gmestanley closed 7 years ago

gmestanley commented 7 years ago

When I tried to build my game with anim8, LÖVE gave me this error: http://image.prntscr.com/image/2e7e915823f54e30aca049413725c6fb.png

I don't know why this is happening. Here's my code:


local anim8 = require "anim8-master/anim8"

function love.load()
    map_01 = love.graphics.newImage("map_01.png")
    spr_reimu = love.graphics.newImage("spr_reimu.png")
    local g = anim8.newGrid(48, 62, spr_reimu:getWidth(), spr_reimu:getHeight())
    local animation = anim8.newAnimation(g('1-3',1), 0.1)
end

function love.update(dt)
  animation:update(dt)
end

function love.draw()
    love.graphics.draw(map_01)
    animation:draw(spr_reimu, 100, 200)
end
kikito commented 7 years ago

Anim8 makes animations by using images divided in a grid. The first two parameters of anim8.newGrid are the dimensions of each frame in the grid. In your case, they are 48 and 62. This means that the image that must be used for the animation will be in a grid where the top-left frame (x=1, y=1) will be on the image coordinates 0,0. The one to the right (x=2, y=1) will be on the image coordinates 49,0. The next one to the right (x=3, y=1) would be on the image coordinates 97,0. And so on.

The error you pasted indicates that you tried to access the frame on x=6, y=1. That would be at 289,0. If your image is less wide than 289+48 pixels, anim8 will raise an error, because you would be trying to access a frame outside of the image.

I must also say that the error that you pastd is unlikely to be provoked by the code that you pasted, since it goes from x=1 to x=3, not x=6. Maybe there's a typo somewhere.

gmestanley commented 7 years ago

Yeah, I entered wrong numbers in there. Sorry to bother you.