I've just started with LÖVE and I've been following the tutorials on the wiki. I searched the forums for animated sprite sheets and came up with AnAl (which seems to be discontinued for 0.7.x). And using quads, I couldn't find any information as to how to go about animating a sprite sheet with quads. Would anyone be able to give a snippet/example or a link to a tutorial. Any help would be greatly appreciated.
- BlueDigit1250
How to create animations from sprite sheets?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 3
- Joined: Sun Jul 24, 2011 3:05 am
Re: How to create animations from sprite sheets?
I don't have a specific example on hand, but the idea is to have a series of images (or a series of quads on one large image) and iterate through them with a timed loop. Whenever I learn something new I generally look at a library that has done it before (AnAL in this case) and try to adapt it to something that suits my needs.
Good Luck!
Good Luck!
-
- Prole
- Posts: 3
- Joined: Sun Jul 24, 2011 3:05 am
Re: How to create animations from sprite sheets?
Thanks for the quick reply, I know what sprite sheets are and have made them before. I'm a beginner at programming and I realised after looking at the demos that I had to include the AnAl.lua file as a module...
Like I said I'm a beginner programmer in fact lets just say this is my first time programming, because it may as well be. What language, if not lua, do you recommend me starting in?
- BlueDigit1250
Like I said I'm a beginner programmer in fact lets just say this is my first time programming, because it may as well be. What language, if not lua, do you recommend me starting in?
- BlueDigit1250
Re: How to create animations from sprite sheets?
Code: Select all
self.frame = 0
self.hitanimation = {}
self.hitanimation[0] = love.graphics.newQuad(0,0, 10,10,self.width,self.height )
--self.width and self.height - is total size of image
--0,0 x y point in pixels in your image where your first frame starts from
-- 10 ,10 size of the first frame
self.hitanimation[1] = love.graphics.newQuad(10,0,10,10,self.width,self.height )
--etc
self.hitanimation[2] = love.graphics.newQuad(20,0,10,10,self.width,self.height )
-etc
self.hitanimation[3] = love.graphics.newQuad(30,0,10,10,self.width,self.height )
--etc
--if update function past some thing like this for calculate what frame show in current dt
love.update(dt)
self.frame = (self.frame + 20*dt) % 4
--and in the draw function past render func
love.draw()
local frame=math.floor(self.frame)
love.graphics.drawq(self.image,self.hitanimation[frame],drawX,drawY)
end
--this will be simple loop animation in 4 frames
Re: How to create animations from sprite sheets?
Lua is a good language to start with.BlueDigit1250 wrote: Like I said I'm a beginner programmer in fact lets just say this is my first time programming, because it may as well be. What language, if not lua, do you recommend me starting in?
- BlueDigit1250
Re: How to create animations from sprite sheets?
Yep, that's the way to do it.NC22 wrote:Code: Select all
self.frame = 0 self.hitanimation = {} self.hitanimation[0] = love.graphics.newQuad(0,0, 10,10,self.width,self.height ) --self.width and self.height - is total size of image --0,0 x y point in pixels in your image where your first frame starts from -- 10 ,10 size of the first frame self.hitanimation[1] = love.graphics.newQuad(10,0,10,10,self.width,self.height ) --etc self.hitanimation[2] = love.graphics.newQuad(20,0,10,10,self.width,self.height ) -etc self.hitanimation[3] = love.graphics.newQuad(30,0,10,10,self.width,self.height ) --etc --if update function past some thing like this for calculate what frame show in current dt love.update(dt) self.frame = (self.frame + 20*dt) % 4 --and in the draw function past render func love.draw() local frame=math.floor(self.frame) love.graphics.drawq(self.image,self.hitanimation[frame],drawX,drawY) end --this will be simple loop animation in 4 frames
It's also possible to generate the quad information procedurally.
Code: Select all
local w = tileset:getWidth ( )
local h = tileset:getHeight ( )
local cols = w / 128
local rows = h / 128
for i = 1, cols * rows, 1 do
local frame = i - 1
local x = frame % cols * 128
local y = math.floor ( frame / cols ) * 128
quads[i] = love.graphics.newQuad ( x, y, 128, 128, w, h )
end
Check this out.
-
- Prole
- Posts: 3
- Joined: Sun Jul 24, 2011 3:05 am
Re: How to create animations from sprite sheets?
Thank you all so much for your help, I'll try it out very shortly.
- BlueDigit1250
- BlueDigit1250
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 8 guests