Page 1 of 1

anim8 - initializing bullet animations during runtime

Posted: Fri Sep 02, 2016 4:41 am
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.

Re: anim8 - initializing bullet animations during runtime

Posted: Fri Sep 02, 2016 4:43 am
by raidho36

Code: Select all

bullet.animation = animations[ name ]

Re: anim8 - initializing bullet animations during runtime

Posted: Fri Sep 02, 2016 4:46 am
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.