This resource is compatible with either BGE or UPBGE 0.2x versions (legacy versions). Post originally posted here.
TL;TR
There’s two ways to restrict your texture color only to black or white colors.
W/ Material Nodes
- Use the
Hue Saturation Valuematerial node to restrict a texture or material’s color to only black or white by forcing theValuesetting to have a number of either be0.0or1.0.
W/O Material Nodes
- In the bottom of your
Properties Editor - Texture Tab:- Enable the
RGB to Intensitysetting. - Set the RGB to Intensity
Colorinput to solid black(R:0.0, G:0.0, B:0.0). - Lastly, toggle the
Negativesetting depending on whether you want your material / texture color to beblackorwhite.
- Enable the
Replace Material - Script
- If you want to replace certain UIs with one color, but different for others, here’s a script that will automatically assign a material for an object depending on if that object has a certain game-property.
- Feel free to tweak the names of the game-properties and object with the replacement materials that the script will be looking for in the active scene.
UI_White&UI_Blackare material names, whileTextured_Objectis the name of the object that already has have the material names assigned to it for easy reference and material tweaking.
import bge
def main(self):
for o in self.owner.scene.objects:
for p in o.getPropertyNames():
if p == "UI_White":
o.meshes[0].replaceMaterial(0, self.owner.scene.objects["Textured_Object"].meshes[0].materials[0])
elif p == "UI_Black":
o.meshes[0].replaceMaterial(0, self.owner.scene.objects["Textured_Object"].meshes[0].materials[1])

