Best way of changing sprites with multiple states?
Posted: Sat Aug 08, 2015 1:35 pm
Working on a mod that adds an item with around a dozen different states, each with it's own sprite. I've managed to cobble together a solution that works - the functional part of the item is an invisible lamp, and my control.lua handles creating and destroying the two parts together. But the only way I've come up with so far to handle changing the sprite for the different states is to have a different version of the visible part for each state, each with a different sprite, and to destroy and replace them whenever the state changes.
If it were just two states, I could use a lamp, but not seeing that as an option with 12 (possibly to become 13 or 14 by the time I'm done). Is there a better way to handle this? Perhaps some way to have an animated sprite but with me in direct control of which frame is visible instead of letting the animation cycle normally? Not seen anything like that in my poking so far, but I'm still quite new to factorio's api and may be missing something obvious.
update been going ahead with the best plan I had, and realized that my hacky approach of replacing the item means dust is constantly being kicked up from placement whenever the state changes (on top of the fact that it feels like a dirty approach to begin with). Oddly, at one point it was not kicking up dust, but I don't know what I was doing differently that could've caused that, so I'm inclined to think it was a bug or something? Anyway. Sigh. Hopefully there's a better way...
If it were just two states, I could use a lamp, but not seeing that as an option with 12 (possibly to become 13 or 14 by the time I'm done). Is there a better way to handle this? Perhaps some way to have an animated sprite but with me in direct control of which frame is visible instead of letting the animation cycle normally? Not seen anything like that in my poking so far, but I'm still quite new to factorio's api and may be missing something obvious.
update been going ahead with the best plan I had, and realized that my hacky approach of replacing the item means dust is constantly being kicked up from placement whenever the state changes (on top of the fact that it feels like a dirty approach to begin with). Oddly, at one point it was not kicking up dust, but I don't know what I was doing differently that could've caused that, so I'm inclined to think it was a bug or something? Anyway. Sigh. Hopefully there's a better way...