Best way of changing sprites with multiple states?

Place to get help with not working mods / modding interface.
Post Reply
GopherAtl
Fast Inserter
Fast Inserter
Posts: 177
Joined: Sat Jan 31, 2015 7:54 pm
Contact:

Best way of changing sprites with multiple states?

Post by GopherAtl »

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...
My Mods:
Nixie Tubes - numeric displays for your circuit networks!
Logistic Combinators - use logistics values in circuit logic! -
Autowire - automate red/green wire connections

GopherAtl
Fast Inserter
Fast Inserter
Posts: 177
Joined: Sat Jan 31, 2015 7:54 pm
Contact:

Re: Best way of changing sprites with multiple states?

Post by GopherAtl »

Found what I think is the best solution - using a car.Tried it out, and it works with just a single layer of 1-frame animations, and I can pick frames to display at will by setting the orientation. Still feels slightly dirty, but it beats the hell out of the constant creating and destroying entities every time the state changes.
My Mods:
Nixie Tubes - numeric displays for your circuit networks!
Logistic Combinators - use logistics values in circuit logic! -
Autowire - automate red/green wire connections

Post Reply

Return to “Modding help”