How to make animation?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to make animation?
I want to create animated death of enemies, and animations when they hit bullet. But i dont want to use any modules, because my animation is to easy for this(1-2 frames, mb 5). So, what should i do?
- Attachments
-
- Project.love
- (13.94 MiB) Downloaded 136 times
Re: How to make animation?
No animation is "to easy" to use a animation library (like anim8)
Anyway, if you really want to do it manually you could create a table which later contains all frames. set the image frame width and height and the spritesheet you want to use and also set a delay you would like to have. Then use love.graphics.newQuad for each frame in your image and save it to the table. Now you just need to update a timer which changes the current frame everytime the given "delay" is reached and if you got the last item in your table reset it to the first one.
You also need to create a state variable (playing, paused states).
I really recommend you to use a library
here is a quick example for animation creation:
Anyway, if you really want to do it manually you could create a table which later contains all frames. set the image frame width and height and the spritesheet you want to use and also set a delay you would like to have. Then use love.graphics.newQuad for each frame in your image and save it to the table. Now you just need to update a timer which changes the current frame everytime the given "delay" is reached and if you got the last item in your table reset it to the first one.
You also need to create a state variable (playing, paused states).
I really recommend you to use a library
here is a quick example for animation creation:
Code: Select all
love.graphics.setDefaultFilter("nearest", "nearest")
-- Create a new Animation Object --
-- Note: this method isn't that efficent! --
function newAnimation(imagePath, fw, fh, delay)
local animation = {}
animation.image = love.graphics.newImage(imagePath)
animation.fw = fw
animation.fh = fh
animation.delay = delay or .1
animation.timer = 0
animation.quads = {}
animation.state = "paused"
animation.currentFrame = 1
local iw, ih = animation.image:getDimensions()
for i = 1, iw/fw do
animation.quads[i] = love.graphics.newQuad(animation.fw * i - animation.fw, 0, animation.fw, animation.fh, animation.image:getDimensions())
end
animation.play = function(self)
self.currentFrame = 1
self.state = "playing"
end
animation.pause = function(self)
self.state = "paused"
end
animation.setFrame = function(self, frame)
self.currentFrame = frame
end
animation.resume = function(self)
self.state = "playing"
end
animation.update = function(self, dt)
self.timer = self.timer + dt
if self.timer > self.delay and self.state == "playing" then
if self.currentFrame < #self.quads then self.currentFrame = self.currentFrame+1
else self.currentFrame = 1 end
self.timer = 0
end
end
animation.draw = function(self, x, y, sx, sy, ox, oy, kx, ky)
love.graphics.draw(self.image, self.quads[self.currentFrame], x or 0, y or 0, sx or 1, sy or 1, ox or 0, oy or 0, kx or 0, ky or 0)
end
return animation
end
local men1 = newAnimation("spritesheet.png", 10, 12, .1)
men1:play()
function love.update(dt)
men1:update(dt)
end
function love.draw()
men1:draw(100, 100, 0, 4, 4)
end
function love.keypressed(key)
if key == "escape" then love.event.quit() end
end
Last edited by MadByte on Thu Sep 24, 2015 2:31 pm, edited 1 time in total.
Re: How to make animation?
Oh sh**. I should really use ani8
But anyway, thank you very much
But anyway, thank you very much
Re: How to make animation?
Well, now i got another problem.
"There is no frame for x=1, y=1"
I have watched tutorials here https://github.com/kikito/anim8, and made all step-by-step. Created framed sprite sheet, i know size of all canvas, i made all pixel-by-pixel, so i just cant understand where is the problem .
What can be the problem? Can u help me?
"There is no frame for x=1, y=1"
I have watched tutorials here https://github.com/kikito/anim8, and made all step-by-step. Created framed sprite sheet, i know size of all canvas, i made all pixel-by-pixel, so i just cant understand where is the problem .
What can be the problem? Can u help me?
- Attachments
-
- Project.love
- Some error(and i dont know why)
- (13.97 MiB) Downloaded 165 times
Re: How to make animation?
Either your grid or image size is wrong, anim8 can't find the first sprite because of this.LavX64 wrote:Well, now i got another problem.
"There is no frame for x=1, y=1"
I have watched tutorials here https://github.com/kikito/anim8, and made all step-by-step. Created framed sprite sheet, i know size of all canvas, i made all pixel-by-pixel, so i just cant understand where is the problem .
What can be the problem? Can u help me?
Re: How to make animation?
Yep, but i made it pixel-by-pixel, so cant understand where problem exactly is.S0lll0s wrote: Either your grid or image size is wrong, anim8 can't find the first sprite because of this.
Re: How to make animation?
Ah, anyway i can't do it properly. Help me plz :C
- Attachments
-
- Project.love
- (13.97 MiB) Downloaded 154 times
Re: How to make animation?
Hey man, the code is really messed up. I had to spend 30 minutes to understand what's going on..
Maybe you can try using AnAL (Animation And Love) Get it here: https://love2d.org/wiki/AnAL
It says that it's outdated but it's really easy for beginners in my opinion.
Maybe you can try using AnAL (Animation And Love) Get it here: https://love2d.org/wiki/AnAL
It says that it's outdated but it's really easy for beginners in my opinion.
Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeooow!!
Re: How to make animation?
Yeah I love AnAL No but seriosuly, it's a great library for animation, also very simple to use.NickRock wrote:Hey man, the code is really messed up. I had to spend 30 minutes to understand what's going on..
Maybe you can try using AnAL (Animation And Love) Get it here: https://love2d.org/wiki/AnAL
It says that it's outdated but it's really easy for beginners in my opinion.
Re: How to make animation?
Yeeeep. My code so sh**ty
But its my like 1st try, so i will grow up in this buisness. And thx for all your help) I really appreciate
But its my like 1st try, so i will grow up in this buisness. And thx for all your help) I really appreciate
Who is online
Users browsing this forum: Bing [Bot] and 4 guests