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.
Is There any way to make an Animation without Quads?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- 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?
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
- 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?
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.
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 True 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.
- 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?
Is there any tutorial on how to do this?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.
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
Re: Is There any way to make an Animation without Quads?
quads are better, but if you are inexperienced with quads you can use thisJacKobOriginal wrote: ↑Thu Mar 22, 2018 12:29 pmIs there any tutorial on how to do this?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.
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?
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
As said by PGUp though, Quads are better and I'd suggest using them in the long term or for larger amounts of sprites.
- 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?
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.
I mean you can have them all as separate images but it's just a lot more work and maintanence.
- 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?
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.PGUp wrote: ↑Thu Mar 22, 2018 12:52 pmquads are better, but if you are inexperienced with quads you can use thisJacKobOriginal wrote: ↑Thu Mar 22, 2018 12:29 pmIs there any tutorial on how to do this?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.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
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
- 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?
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?JacKobOriginal wrote: ↑Sat Mar 24, 2018 1:29 pmI 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.PGUp wrote: ↑Thu Mar 22, 2018 12:52 pmquads are better, but if you are inexperienced with quads you can use thisCode: 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
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
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
- 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?
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 True 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.
- 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?
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
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
Who is online
Users browsing this forum: Ahrefs [Bot] and 12 guests