How to create an animation from a .png image (without quads)?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
free.gen
Prole
Posts: 1
Joined: Fri Sep 27, 2019 1:16 pm

How to create an animation from a .png image (without quads)?

Post by free.gen »

Hello to all! I just started to learn the LUA, and I need help with the animation. I googled my question for a very long time, but nothing worked out for me. :( I hope you'll give me a hand.

It's simple - I want my PNG picture to do this:

-appeared smoothly at a given point,
-moved down by 10px
-faded away
-after disappearing, nothing happens for 2 seconds
-the cycle starts anew (again from a given point)

I tried to do this with quads, but that doesn't suit me.
I made a gif animation to show what kind of animation I need.
Attachments
arrow.gif
arrow.gif (71.81 KiB) Viewed 5107 times
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: How to create an animation from a .png image (without quads)?

Post by MrFariator »

By quads, I presume you tried making a sprite sheet with each of the individual frames? For an animation like this, you could very well just code the animation with love.graphics.setColor to change the transparency, and then just adjusting the draw coordinates you pass to love.graphics.draw. You could load the image of the arrow as a quad or as its own image, doesn't really make much of a difference.
User avatar
YoungNeer
Party member
Posts: 118
Joined: Wed May 15, 2019 7:49 am

Re: How to create an animation from a .png image (without quads)?

Post by YoungNeer »

First of all - welcome to the forums. Generally we don't "make your games" as zorg pointed out in this post but since you are completely newbie - I'll not bother you with the rules.

So there are couple of ways you could do that

1. Use pgimeno's gifloading library available at here (has some issues though)
2. Don't work with quads - use Iffy
3. The solution that you wanted - Anima

I am uploading a possible solution here - but please note that Anima is still under active development and a lot of things will change so please use the library that goes with this love file (and don't git clone for now)
Attachments
animation.love
(4.23 KiB) Downloaded 167 times
My Github- your contribution is highly appreciated
monolifed
Party member
Posts: 188
Joined: Sat Feb 06, 2016 9:42 pm

Re: How to create an animation from a .png image (without quads)?

Post by monolifed »

move image y coord to y + 10
setColor from {1,1,1,1} to {1,1,1,0} before drawing the image

you can probably use https://github.com/kikito/tween.lua
(note: image may not appear smooth with non integer y-coord)
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How to create an animation from a .png image (without quads)?

Post by raidho36 »

free.gen wrote: Fri Sep 27, 2019 1:45 pm I tried to do this with quads, but that doesn't suit me.
At the bottom level it will be done with quads anyhow, that's right about the only reasonable way to render sprites (the other being sprite mesh which is like quads except much more complicated to do and yields substantially less GPU overdraw). You can write a code that generates and renders all the relevant quads automatically. There are libraries that have this functionality already written by someone else.

This kind of animation can be done programmatically using a single static sprite. If you want to use individual separate frames to animate things, then go ahead and do just that. It's not like modern GPUs are in any shortage of VRAM to store your graphics.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to create an animation from a .png image (without quads)?

Post by pgimeno »

YoungNeer wrote: Fri Sep 27, 2019 3:09 pm 1. Use pgimeno's gifloading library available at here (has some issues though)
I don't recommend this approach. That extends the load time and used memory unnecessarily. Also, GIFs can't do anti-aliasing via alpha, as they don't support partially transparent pixels.
User avatar
YoungNeer
Party member
Posts: 118
Joined: Wed May 15, 2019 7:49 am

Re: How to create an animation from a .png image (without quads)?

Post by YoungNeer »

pgimeno wrote: Fri Sep 27, 2019 10:01 pm Also, GIFs can't do anti-aliasing via alpha, as they don't support partially transparent pixels.
Nice catch! I forgot that gifs can't be partially transparent
My Github- your contribution is highly appreciated
Post Reply

Who is online

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