anim8 - initializing bullet animations during runtime

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
JohnnyC
Prole
Posts: 16
Joined: Mon Aug 15, 2016 11:39 pm

anim8 - initializing bullet animations during runtime

Post by JohnnyC »

Right now I'm struggling with a good way to manage initializing different bullet animations during runtime using anim8. Right now I have an animations table that has all my animations for bullets that is loaded at the beginning.

Code: Select all

{
redBullet = anim8.newAnimation(b(3,8), 0.1),
redFire = anim8.newAnimation(b2('1-4',1),0.2):flipV(),
yellowGlobe = anim8.newAnimation(b(13,11),1)
etc...
}
And whenever an enemy creates a new bullet it runs a function called getAnim(name). Name is a variable that is passed by the enemy when it creates a new bullet.

Code: Select all

if anim == 'redFire' then
    bullet.animation = animations.redBullet
elseif anim == 'redBullet' then
    bullet.animation = animations.redFire
elseif anim...etc...
It works but I feel like it is not a very good method of doing this, it looks very sloppy. Especially if I eventually have like 20+ bullet designs. Also the only way I can get this to work is if the animations table is global. It just seems like there is an obvious solution I'm missing.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: anim8 - initializing bullet animations during runtime

Post by raidho36 »

Code: Select all

bullet.animation = animations[ name ]
JohnnyC
Prole
Posts: 16
Joined: Mon Aug 15, 2016 11:39 pm

Re: anim8 - initializing bullet animations during runtime

Post by JohnnyC »

raidho36 wrote:

Code: Select all

bullet.animation = animations[ name ]
hahaha
I knew there was a more obvious way. It's pretty crushing how obvious it turned out to be.
Thanks.
Post Reply

Who is online

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