Changing graphics of entity at runtime

Place to get help with not working mods / modding interface.
trold
Inserter
Inserter
Posts: 45
Joined: Fri Jul 31, 2015 1:07 pm
Contact:

Changing graphics of entity at runtime

Post 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?
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Changing graphics of entity at runtime

Post 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
Last edited by Nexela on Mon Dec 19, 2016 2:56 pm, edited 1 time in total.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Changing graphics of entity at runtime

Post 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.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Changing graphics of entity at runtime

Post by darkfrei »

By harvester mod Autor changed the entity from "harvester" to "harvester-animation", then back.
trold
Inserter
Inserter
Posts: 45
Joined: Fri Jul 31, 2015 1:07 pm
Contact:

Re: Changing graphics of entity at runtime

Post 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?
Post Reply

Return to “Modding help”