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.