How can I make short animations in LOVE?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Lvix
Prole
Posts: 6
Joined: Sun Aug 06, 2017 5:53 am

How can I make short animations in LOVE?

Post by Lvix »

I'm a newbie to LOVE and I have no game programming experience.
I just started learning LOVE many days ago.
I'm wondering how to make short animations. I mean, like breaking a barrel, a bomb exploding etc. However, I don't have any actual LOVE examples to refer to.
And this is my idea:
1. load each frame of the animation into LOVE
2. draw the images with a time interval
this is my example code:

Code: Select all

function love.load() --	
	ww = love.graphics.getWidth()
	wh = love.graphics.getHeight() --window width and height 
	love.graphics.setBackgroundColor(255,255,255,255)
	redtangle:init() --load images 
end

function love.draw()
	redtangle:draw()
end

function love.update(dt) --
	redtangle:play()
end

redtangle = {
	frames = {},
	playFrame = 1, 
	playCount = 0, 
	playInterval = 10, --each frame lasts 10 * dt
}
  
	
function redtangle:init()
  local tName 
	for i = 1, 4 do 
		tName = "p"..tostring(i)..".png" --load images, p1.png to p4.png
		self.frames[i] = love.graphics.newImage(tName)
	end 
end

function redtangle:play()
	self.playCount = self.playCount + 1
	if self.playCount > self.playInterval then
		self.playCount = 0
		self.playFrame = self.playFrame + 1 --switch to next frame 
		if self.playFrame > 4 then
			self.playFrame = 1 
		end
	end
end

function redtangle:draw()
	local rx, ry = ww/2 - 125, wh/2 - 125
	love.graphics.draw(self.frames[self.playFrame], rx, ry) --draw
end
files:
TIM20170820033454.jpg
TIM20170820033454.jpg (11.28 KiB) Viewed 3755 times
it looks like this:
bbb.gif
bbb.gif (12.15 KiB) Viewed 3755 times
Is this a proper way to make animations?
g0r1ll4
Prole
Posts: 5
Joined: Mon Aug 07, 2017 3:59 am

Re: How can I make short animations in LOVE?

Post by g0r1ll4 »

A better way is to use a sprite sheet and use a quad to divide it.

Link is a pretty clear tutorial about it:
https://www.youtube.com/watch?v=_NpDbNtJyDQ
User avatar
Lvix
Prole
Posts: 6
Joined: Sun Aug 06, 2017 5:53 am

Re: How can I make short animations in LOVE?

Post by Lvix »

g0r1ll4 wrote: Sat Aug 19, 2017 9:47 pm A better way is to use a sprite sheet and use a quad to divide it.

Link is a pretty clear tutorial about it:
https://www.youtube.com/watch?v=_NpDbNtJyDQ
Thanks a lot! :awesome:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests