Is There any way to make an Animation without Quads?

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.
User avatar
JacKobOriginal
Prole
Posts: 11
Joined: Thu Mar 22, 2018 12:05 am
Location: Colombia
Contact:

Is There any way to make an Animation without Quads?

Post by JacKobOriginal »

Let's say if I had a 3 frame. 15x23 sprite, but the frames were saved individually as .png files.
Am I obligated to use Quads when making an animation or is there another way to do it?

Any help would be greatly appreciated.
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Is There any way to make an Animation without Quads?

Post by zorg »

Hi and welcome to the forums.

If you have the frames in separate files, then loading them as separate images does not require you to use quads; quads are useful if you want to display a part of a bigger image only (with or without using spritebatches).

That said, it may be faster the latter way.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
JacKobOriginal
Prole
Posts: 11
Joined: Thu Mar 22, 2018 12:05 am
Location: Colombia
Contact:

Re: Is There any way to make an Animation without Quads?

Post by JacKobOriginal »

zorg wrote: Thu Mar 22, 2018 2:07 am Hi and welcome to the forums.

If you have the frames in separate files, then loading them as separate images does not require you to use quads; quads are useful if you want to display a part of a bigger image only (with or without using spritebatches).

That said, it may be faster the latter way.
Is there any tutorial on how to do this?
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

Re: Is There any way to make an Animation without Quads?

Post by PGUp »

JacKobOriginal wrote: Thu Mar 22, 2018 12:29 pm
zorg wrote: Thu Mar 22, 2018 2:07 am Hi and welcome to the forums.

If you have the frames in separate files, then loading them as separate images does not require you to use quads; quads are useful if you want to display a part of a bigger image only (with or without using spritebatches).

That said, it may be faster the latter way.
Is there any tutorial on how to do this?
quads are better, but if you are inexperienced with quads you can use this

Code: Select all

function love.load()
sprites = {}
sprites[1] = love.graphics.newImage("sprite1.png")
sprites[2] = love.graphics.newImage("sprite2.png")
sprites[3] = love.graphics.newImage("sprite3.png")
frame = 1
end

function love.update()
frame = frame + 1
if frame > 3 then
frame = 1
end
end

function love.draw()
love.graphics.draw(sprites[frame])
end
-
Tst_
Prole
Posts: 7
Joined: Tue Dec 23, 2014 10:11 pm

Re: Is There any way to make an Animation without Quads?

Post by Tst_ »

Code: Select all

--[[ 
	This function will take a directory I.E: "images", search that directory for PNGs, load said images
	into a table indexed by the filename of the image minus the file extension or false if the directory
	does not exist.
	
	Arguments:
		DIR: Directory
		EXT: File extension I.E: "png"
]]--
function loadImagesFromDir(dir,ext)
	if love.filesystem.isDirectory(dir) then
		--Make sure the directory exists before we do anything.
		
		local ext == ext:lower()
		--Make sure it's lowercase for the comparison later on, stuff works better if it's all the same case.
		
		local imageList = {}
   		imageList = love.filesystem.getDirectoryItems(dir)
   		--Get a list of things in the directory, (Could probably use callbacks to handle the name checking
   		--but I've never used them so I can't tell you how to do it that way)
   		
   		if #imageList == 0 then return false end
   		--Quick check to make sure we don't waste time processing an empty table
   		
   		for k,v in pairs(imageList) do
   			--Go through the list
   			
   			if string.sub(string.lower(v), -4) ~= "."..ext then
   				imageList[k] = nil
   				--If it's not the file type we're looking for, remove it from the array
   			else
   				imageList[string.sub(v, string.len(v)-4)] = love.graphics.newImage(dir.."/"..v)
   				--Import the file as an imageData object ready to be drawn and stick it in the table
   				--with the index of the name of the file
   				
   				imageList[k] = nil
   				--Remove the old string value from the table
   			end
   		end
   		return imageList
   		--Now we've processed everything, return the table
	else
   		return false
   		--Wasn't a correct directory so return false
	end
end


--For you, you could then do something like

function love.load()
	images = loadImagesFromDir("images","png")
end

function love.draw()
	love.graphics.draw(images["test"], 0, 0, 0, 1, 1)
end
I assumed you meant a tutorial on how to automatically load the images from a directory so I made a function that should work, can't test it ATM as I'm away from home base but it should explain it well enough for you to get a good idea of what's going on, if you want quads you can use the same function but change newImage to newQuad and give it the extra arguments it requires.

As said by PGUp though, Quads are better and I'd suggest using them in the long term or for larger amounts of sprites.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Is There any way to make an Animation without Quads?

Post by Jasoco »

I would definitely recommend just using a single sheet with all the frames on it (Even if you just use canvases to assemble them in-game after the fact) and then to make it easier for you, use a library like Anim8 to handle the animation itself.

I mean you can have them all as separate images but it's just a lot more work and maintanence.
User avatar
JacKobOriginal
Prole
Posts: 11
Joined: Thu Mar 22, 2018 12:05 am
Location: Colombia
Contact:

Re: Is There any way to make an Animation without Quads?

Post by JacKobOriginal »

PGUp wrote: Thu Mar 22, 2018 12:52 pm
JacKobOriginal wrote: Thu Mar 22, 2018 12:29 pm
zorg wrote: Thu Mar 22, 2018 2:07 am Hi and welcome to the forums.

If you have the frames in separate files, then loading them as separate images does not require you to use quads; quads are useful if you want to display a part of a bigger image only (with or without using spritebatches).

That said, it may be faster the latter way.
Is there any tutorial on how to do this?
quads are better, but if you are inexperienced with quads you can use this

Code: Select all

function love.load()
sprites = {}
sprites[1] = love.graphics.newImage("sprite1.png")
sprites[2] = love.graphics.newImage("sprite2.png")
sprites[3] = love.graphics.newImage("sprite3.png")
frame = 1
end

function love.update()
frame = frame + 1
if frame > 3 then
frame = 1
end
end

function love.draw()
love.graphics.draw(sprites[frame])
end
I Did what you said, now I am wondering how to put that animation when I move left or right using the "Baseline 2D Platformer" Tutorial.
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
User avatar
JacKobOriginal
Prole
Posts: 11
Joined: Thu Mar 22, 2018 12:05 am
Location: Colombia
Contact:

Re: Is There any way to make an Animation without Quads?

Post by JacKobOriginal »

JacKobOriginal wrote: Sat Mar 24, 2018 1:29 pm
PGUp wrote: Thu Mar 22, 2018 12:52 pm
JacKobOriginal wrote: Thu Mar 22, 2018 12:29 pm

Is there any tutorial on how to do this?
quads are better, but if you are inexperienced with quads you can use this

Code: Select all

function love.load()
sprites = {}
sprites[1] = love.graphics.newImage("sprite1.png")
sprites[2] = love.graphics.newImage("sprite2.png")
sprites[3] = love.graphics.newImage("sprite3.png")
frame = 1
end

function love.update()
frame = frame + 1
if frame > 3 then
frame = 1
end
end

function love.draw()
love.graphics.draw(sprites[frame])
end
I Did what you said, now I am wondering how to put that animation when I move left or right using the "Baseline 2D Platformer" Tutorial.
Ok, so I just now learned how to put that animation in the same place as the player, now my question is, how do i "hide" a sprite?
Let's say if I pressed the jump button, I would hide the standing animation and played the jumping animation, and when it goes past a certain time, it goes back to the standing animation and hides the jumping animation.
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Is There any way to make an Animation without Quads?

Post by zorg »

You hide things by not showing them, i.e. don't draw them during frames you want to not show those sprites.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
JacKobOriginal
Prole
Posts: 11
Joined: Thu Mar 22, 2018 12:05 am
Location: Colombia
Contact:

Re: Is There any way to make an Animation without Quads?

Post by JacKobOriginal »

zorg wrote: Wed Mar 28, 2018 2:49 am You hide things by not showing them, i.e. don't draw them during frames you want to not show those sprites.
And how do I do that in love.update(dt)? I tried putting love.graphics.draw in it but nothing happened when I pressed the button I assigned the animation in.
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 6 guests