[help][bge][python] Set multiple texture

Hi,
i am making a game and i am now working on the options menu where you can set the quality.
It works i can set the quality but it only works for one object


import bge
from bge import *
def main():
  cont = bge.logic.getCurrentController()
  own = cont.owner
  scene = bge.logic.getCurrentScene()
  main = scene.objects["main"] #quality: HIGH, MEDIUM, LOW
  if main["quality"] == "HIGH":
    url_blue = logic.expandPath("//textures/blue_H.jpg")
    url_red = logic.expandPath("//textures/red_H.jpg")
    url_green = logic.expandPath("//textures/green_H.jpg")
  elif main["quality"] == "MEDIUM":
    url_blue = logic.expandPath("//textures/blue_M.jpg")
    url_red = logic.expandPath("//textures/red_M.jpg")
    url_green = logic.expandPath("//textures/green_M.jpg")
  else:
    url_blue = logic.expandPath("//textures/blue_L.jpg")
    url_red = logic.expandPath("//textures/red_L.jpg")
    url_green = logic.expandPath("//textures/green_L.jpg")
  if "blue" in own:
    ID_blue = texture.materialID(own, 'IMblue_H.jpg')
    object_texture = texture.Texture(own, ID_blue)
    new_source = texture.ImageFFmpeg(url_blue)
  elif "red" in own:ID_red = texture.materialID(own, 'IMred_H.jpg')
    object_texture = texture.Texture(own, ID_red)
    new_source = texture.ImageFFmpeg(url_red)
  elif "green" in own:
     ID_green = texture.materialID(own, 'IMgreen_H.jpg')
     object_texture = texture.Texture(own, ID_green)
     new_source = texture.ImageFFmpeg(url_green)
  else:
     ID_blue = texture.materialID(own, 'IMblue_H.jpg')
     object_texture = texture.Texture(own, ID_blue)
     new_source = texture.ImageFFmpeg(url_blue)

  logic.texture = object_texture #here it goes wrong
  logic.texture.source = new_sourcelogic.texture.refresh(False)main() #here it goes wrong
  logic.texture.refresh(True)
main()

How to change on multiple objects the textures?

I think you need to call main at main to set it to main :).

Seriously, you change the texture on each material by using videotexture on each single material. Be aware shared materials will share the texture.

As a mesh can have several materials you can set the source of each single material:


texture = bge.texture.Texture(gameObject, materialID)
otherTexture = bge.texture.Texture(gameObject, otherMaterialID)
anotherTexture = bge.texture.Texture(gameObject, anotherMaterialID)

I suggest to separate the mapping of your properties to image paths into an own function).


def setTexture(object, texture):
    imagePath = retrieveImagePath(object)
    texture.source = texture.ImageFFmpeg(imagePath)
    texture.refresh(False)
...
def retrieveImagePath(object):
    ...
        return logic.expandPath("//textures/green_L.jpg")

thanks Monster.
But i cant get it to work do you have a example?

Dynamic Texture - easy to use VideoTexture (2.68+)

Thanks Monster it works :smiley: