Question: What is the right way to change the graphics of an entity at runtime?
Context: The Bottleneck mod decorates different elements in the factory with a light each, indicating the state of the assembler/drill/furnace/whatever, with different colors for running/starved/congested. Currently, this is done by having different prototypes for each color of light. When the light changes, the old light is destroyed, and a new light is created with the right color. This seems wasteful to me, since the only difference between the old and the new is the graphics. Optimally, I would want something like the normal colored lamps, but it seems like those are tied very intimately into the game engine. The only thing I knew how to do was the destroy/create new cycle, but I hope there is a better way. Thoughts?
Changing graphics of entity at runtime
Re: Changing graphics of entity at runtime
Option #1 viewtopic.php?f=25&t=38570
Option #2 Might also be possible to use a lamp and change it's picture_on color via circuit control behaviors. I haven't looked into this one though. This option would probably have the highest (although only slightly) overhead of the 3 options do to the additional complexity of circuit network logic
Option #2 Might also be possible to use a lamp and change it's picture_on color via circuit control behaviors. I haven't looked into this one though. This option would probably have the highest (although only slightly) overhead of the 3 options do to the additional complexity of circuit network logic
Last edited by Nexela on Mon Dec 19, 2016 2:56 pm, edited 1 time in total.
Re: Changing graphics of entity at runtime
Option #3 that I totally missed and should be even easier then version #1 since you only need 4 pictures (off, green, red, yellow)
Use a prototype that supports 4x rotation and different pictures depending on rotation and just set the direction of the object.
Use a prototype that supports 4x rotation and different pictures depending on rotation and just set the direction of the object.
Re: Changing graphics of entity at runtime
By harvester mod Autor changed the entity from "harvester" to "harvester-animation", then back.
Re: Changing graphics of entity at runtime
Oh, I like that. Very clever, thank you! Is there a list of prototypes that support 4x rotation? From the API, it almost looks like every entity can be made to support rotation through the LuaEntity.supports_direction, or is that sometimes ignored by the engine?Nexela wrote:Option #3 that I totally missed and should be even easier then version #1 since you only need 4 pictures (off, green, red, yellow)
Use a prototype that supports 4x rotation and different pictures depending on rotation and just set the direction of the object.