Page 1 of 1

Changing graphics of entity at runtime

Posted: Mon Dec 19, 2016 12:06 pm
by trold
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?

Re: Changing graphics of entity at runtime

Posted: Mon Dec 19, 2016 1:54 pm
by Nexela
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

Re: Changing graphics of entity at runtime

Posted: Mon Dec 19, 2016 2:49 pm
by Nexela
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.

Re: Changing graphics of entity at runtime

Posted: Mon Dec 19, 2016 6:51 pm
by darkfrei
By harvester mod Autor changed the entity from "harvester" to "harvester-animation", then back.

Re: Changing graphics of entity at runtime

Posted: Tue Dec 20, 2016 7:45 pm
by trold
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.
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?