## [Library] anim8 - An animation library - v2.3.0 released

Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

### Re: [Library] anim8 - An animation library - v1.2.0 released

[quote="kikito"]Can you give me the complete source code, or at least the line where the error happened? What version of anim8 are you using?

Code: Select all

function Animation:draw(image, x, y, r, sx, sy, ox, oy, ...)
local frame = self.frames[self.position]
if self.flippedH or self.flippedV then
r,sx,sy,ox,oy = r or 0, sx or 1, sy or 1, ox or 0, oy or 0
local _,_,w,h = frame:getViewport()

if self.flippedH then
sx = sx * -1
ox = w - ox
end
if self.flippedV then
sy = sy * -1
oy = h - oy
end
end
love.graphics.drawq(sheet1, frame, x, y, r, sx, sy, ox, oy, kx, ky ) --Line 273
end

-----------------------------------------------------------

local anim8 = {
newGrid = newGrid,
newAnimation = newAnimation
}
return anim8

And...............this is the main.lua.

Code: Select all


local anim8 = require 'anim8'
local image, animation

love.physics.setMeter(60)
world = love.physics.newWorld(0, 9.81*64, true)

image = love.graphics.newImage("sheet1.png")
local g = anim8.newGrid(32, 32, image:getWidth(), image: getHeight())
animation = anim8.newAnimation('loop', g('1,1-8'), 0.1)
animation:draw(sheet1, 100, 200)

objects = {} --Creates table "objects"

--The ground
objects.ground = {}
objects.ground.body = love.physics.newBody(world, 650/2, 650-50/2) --2nd & 3rd parameter are used to anchor object.ground to fit in correct place
objects.ground.shape = love.physics.newRectangleShape(650, 50) --Width = 650, Height = 50
objects.ground.fixture = love.physics.newFixture(objects.ground.body, objects.ground.shape) --attach shape to body

--Ball
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic") -- Centering of the ball, made to be dynamic to move.
objects.ball.shape = love.physics.newCircleShape(20) -- Radius = 20
objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1)

--Blocks
objects.block1 = {}
objects.block1.body = love.physics.newBody(world, 200, 550, "dynamic")
objects.block1.shape = love.physics.newRectangleShape(0, 0, 50, 100)
objects.block1.fixture = love.physics.newFixture(objects.block1.body, objects.block1.shape, 5)

objects.block2 = {}
objects.block2.body = love.physics.newBody(world, 200, 400, "dynamic")
objects.block2.shape = love.physics.newRectangleShape(0, 0, 100, 50)
objects.block2.fixture = love.physics.newFixture(objects.block2.body, objects.block2.shape, 2)

love.graphics.setBackgroundColor(101, 64, 251) --Blue background!
love.graphics.setMode(650, 650, false, true, 0) --set the window dimensions to 650 by 650 with no fullscreen, vsync on, and no antialiasing
end

function love.update(dt)
animation:update(dt) -- enables anim8
world:update(dt) --this puts the world into motion

if love.keyboard.isDown("right") then --press the right arrow key to push the ball to the right
objects.ball.body:applyForce(400, 0)
elseif love.keyboard.isDown("left") then --press the left arrow key to push the ball to the left
objects.ball.body:applyForce(-400, 0)
elseif love.keyboard.isDown("up") then --press the up arrow key to set the ball in the air
objects.ball.body:setPosition(650/2, 650/2)
end
end

function love.draw()

love.graphics.setCaption("Mars")
love.graphics.setColor(72, 160, 14) -- set the drawing color to green for the ground
love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints())) -- draw a "filled in" polygon using the ground's coordinates

love.graphics.setColor(193, 47, 14) --set the drawing color to red for the ball

love.graphics.setColor(50, 50, 50) -- set the drawing color to grey for the blocks
love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
love.graphics.polygon("fill", objects.block2.body:getWorldPoints(objects.block2.shape:getPoints()))

end


Stack error:

Error

anim8.lua:273: incorrect parameter type: expected userdata.

Traceback

[C]: in function 'drawq'
anim8.lua:273:in function 'draw'
[C]: in function 'xpcall'
Last edited by Mogex on Fri Dec 07, 2012 9:36 pm, edited 2 times in total.

Roland_Yonaba
Inner party member
Posts: 1562
Joined: Tue Jun 21, 2011 6:08 pm
Contact:

### Re: [Library] anim8 - An animation library - v1.2.0 released

Mogex wrote:Oh and whats with all of the "obey" avatars?
Oh that ?
A monstrous conspiracy.
You're strongly encouraged to join the resistance. We have cakes.

Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

### Re: [Library] anim8 - An animation library - v1.2.0 released

Bump, so the edit can be seen.

kikito
Inner party member
Posts: 3152
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: [Library] anim8 - An animation library - v1.2.0 released

Well, the issue seems very simple. You have named your image variable image,

Code: Select all

image = love.graphics.newImage("sheet1.png")
But when you are using it to draw the animation, you are calling it sheet1:

Code: Select all

animation:draw(sheet1, 100, 200)
sheet1 has not been declared before, so Lua assigns it the value "nil". You are passing nil to love.graphics.drawq, as I suspected. That's why you are getting that error.

Replacing sheet1 by image on that line will probably get rid of it, but will still not draw the animation. In order for it to appear, you will have to move the animation:draw(image, 100, 200) line inside the love.draw function.
When I write def I mean function.

shatterblast
Party member
Posts: 136
Joined: Tue Dec 11, 2012 9:47 pm
Location: Dallas, Texas, USA

### Re: [Library] anim8 - An animation library - v1.2.0 released

Hello! I'm new to Love 2D and to Lua in general. I could use a little help please. I'm trying to animate with an image grid, using Anim8 1.2 and Love 2D version 0.8. In general, I'm trying to render some nifty particle effects as animations instead of using a particle engine.

Anim8 seemed highly recommended so I thought I would give it a try. I have a test PNG image with a size of 960 by 4224. Each frame is 192 by 192 and has no borders. This creates a sheet of 5 frames by 22 frames for a total of 110 frames. I hope I'm not coming across as confusing.

Anyhow, I get an error message that says: There is no frame for x=6, y=1.

My code that I've tried editing from the README:

Code: Select all

local anim8 = require 'anim8'

imageTest = love.graphics.newImage('media/sparkle_test.png')

local testGrid = anim8.newGrid(192, 192, 960, 4224)
animationTest = anim8.newAnimation('loop', testGrid('1-110, 1'))
end

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

function love.draw()
animationTest:draw(imageTest, 100, 200)
end


And the image:
http://postimage.org/image/662nctz8p/

Thanks for any attention.

Uhfgood
Prole
Posts: 35
Joined: Sat Jul 28, 2012 10:04 pm
Location: Oregon, US
Contact:

### Re: [Library] anim8 - An animation library - v1.2.0 released

Quick question about delays (defaultDelay specifically) -- what does that number represent. Seconds? milliseconds? something else?

kikito
Inner party member
Posts: 3152
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: [Library] anim8 - An animation library - v1.2.0 released

shatterblast wrote:I could use a little help please. I'm trying to animate with an image grid, using Anim8 1.2 and Love 2D version 0.8. In general, I'm trying to render some nifty particle effects as animations instead of using a particle engine.
[...]
Anyhow, I get an error message that says: There is no frame for x=6, y=1.
Hi Shatterblast, I'm sorry, I didn't read your message until now. From what I'm reading in other post, you are already using AnAL, so this answer will probably not serve you. Let me answer in case someone else has the same issue.

When you write this,

Code: Select all

animationTest = anim8.newAnimation('loop', testGrid('1-110, 1'))
Anim8 understands "Create an animation with the first 110 frames of the first row". The "x" coordinate goes from 1 to 110, and the "y" coordinate is "fixed" in 1.

But in your case, your animation takes several rows. I suspect this is probably what you need:

Code: Select all

animationTest = anim8.newAnimation('loop', testGrid('1-5,1-22'))
Now this says "x goes from 1 to 5, and y goes from 1 to 22".
Uhfgood wrote:Quick question about delays (defaultDelay specifically) -- what does that number represent. Seconds? milliseconds? something else?
It depends on the dt what you pass to animation:update(dt). If dt is in seconds, then the time delays will be in seconds too. This is the usual case, if you are just using LÖVE's default dt as provided in love.update.

You can use numbers smaller than 1, like 0.1, 0.25, etc.
When I write def I mean function.

Uhfgood
Prole
Posts: 35
Joined: Sat Jul 28, 2012 10:04 pm
Location: Oregon, US
Contact:

### Re: [Library] anim8 - An animation library - v1.2.0 released

So delays are in the range of 0 - 1?

I'm using a kind of fixed frame rate code. Approximately 60 fps. Essentially I pass 1/60 into my time. So I'm still a bit unsure. (the dt value passed to my code is usually 0.0166666)

kikito
Inner party member
Posts: 3152
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: [Library] anim8 - An animation library - v1.2.0 released

Uhfgood wrote:So delays are in the range of 0 - 1?
It depends on your animation. If each frame of your animation takes less than 1 second to execute, then yes, the delays will be in 0..1. If one or more frames of your animation take longer than 1 second, then the ranges can be different.
Uhfgood wrote:I'm using a kind of fixed frame rate code. Approximately 60 fps. Essentially I pass 1/60 into my time. So I'm still a bit unsure. (the dt value passed to my code is usually 0.0166666)
Usually, the smaller the dt, the better. Anim8 internally "adds" the time that has passed for each animaton. It's prepared for handling variable framerate. If your framerate is stable, that's great. But that should not affect anim8 in any way. Just pass your dt to animation:update, and it'll handle the details.
Last edited by kikito on Wed Apr 03, 2013 8:47 pm, edited 1 time in total.
When I write def I mean function.

Septi
Prole
Posts: 2
Joined: Wed Apr 03, 2013 12:46 pm

### Re: [Library] anim8 - An animation library - v1.2.0 released

I just cloned anim 8 from the Git repo, and here's an error I'm getting:

Code: Select all

Error: [string "3rdparty/anim8/anim8.lua"]:259: attempt to index field 'frames' (a nil value)
stack traceback:
[string "3rdparty/anim8/anim8.lua"]:259: in function 'draw'
[string "main.lua"]:16: in function 'draw'
[string "boot.lua"]:323: in function <[string "boot.lua"]:308>
[C]: in function 'xpcall'
My main.lua file looks like this:

Code: Select all

local anim8 = require '3rdparty/anim8/anim8.lua'

local image, animation

image = love.graphics.newImage ('media/pumpking.png')
local g = anim8.newGrid (46, 46, image:getWidth(), image:getHeight())
animation = anim8.newAnimation ('loop', g ('3,1-3'), 0.1)
end

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

function love.draw()
animation.draw (image, 400, 300)
end
Is something wrong with anim8, or did I do something stupid? Please be forgiving, I'm very new both to Lua and Love.

### Who is online

Users browsing this forum: No registered users and 2 guests