[LIB]Animated textures

Started by Sam_, September 26, 2018, 05:42:16 AM

Previous topic - Next topic

Sam_

I've always hoped that the base game would have some kind of support for animated buildings, items and textures in general, but so far all we have is specific hard-coded animations for the windmill and waterwheel. These buildings use code rather then image data to animate, and they are not abstracted for modders to use, either by inheritance or XML. So, I went ahead and made it myself and decided to share since there didn't seem to be an easy to use utility on the forum.

The .dll adds a graphic class that any Thing should be able to use. For now it only behaves like Graphic_Single, but in future I could probably expand it to include animated Graphic_Multi functionality. In addition to the graphic class there's a CompProperties you can use to modify the frame speed and whether it's randomised. For now it's rather simple, and barely tested, but it works.

As for the actual texture, the mod below has a demonstration, it currently only uses a folder of .pngs, rather then a .gif or anything else, the same way that Graphic_StackCount does. Which probably limits it to 26 frames as each texture ends with a letter. The utility isn't really intended for complex animation anyway, and I haven't tested the impact that such an animation will have on performance, if any.

I've created a small mod with a useless building as a tutorial here.
You can also get the source code here.

Here is the building as it looks in game. (Note the animation speed differs, but you can change that in the XML easily)


If you're interested tear this apart and let me know what kind of bugs or problems you encounter.


Elendil

Thanks a lot, I'll take look :).

Flyingstar

Thank you for making useful code. I'm still using it well.
The original code still works fine with Rimworld 1.2. But just in case, I updated target NET framework version to 4.7.2.
https://drive.google.com/file/d/1koJjjphTi7tTU8dOZgEuUg3b_PrANHzL/view?usp=sharing

Flyingstar

As of 1.3, the problem arose. Buildings that use animation graphicClass will spam errors while their blueprint queue exist on the map.