Page 1 of 2

Is There any way to make an Animation without Quads?

Posted: Thu Mar 22, 2018 1:13 am
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.

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

Posted: Thu Mar 22, 2018 2:07 am
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.

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

Posted: Thu Mar 22, 2018 12:29 pm
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?

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

Posted: Thu Mar 22, 2018 12:52 pm
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

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

Posted: Thu Mar 22, 2018 1:12 pm
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.

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

Posted: Fri Mar 23, 2018 12:57 am
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.

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

Posted: Sat Mar 24, 2018 1:29 pm
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.

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

Posted: Wed Mar 28, 2018 12:40 am
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.

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

Posted: Wed Mar 28, 2018 2:49 am
by zorg
You hide things by not showing them, i.e. don't draw them during frames you want to not show those sprites.

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

Posted: Wed Mar 28, 2018 2:21 pm
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.