How to replace texture in BGE?

Game Engine, Players & Web Plug-in, Virtual Reality, support for other engines

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Sun Feb 10, 2013 4:59 pm

How to replace texture in BGE?

Post by lolb »

Blender documentation regarding the use of dynamic texture in BGE ( makes it clear that if necessary, we also have the ability to use a texture that already exists for reuse:

Create texture
VideoTexture.Texture is the class that creates the Texture object that loads the dynamic texture on the GPU. The constructor takes one mandatory and three optional arguments:
The game object.
Material index as returned by VideoTexture.materialID(), 0 = first material by default.
Texture index in case of multi-texture channel, 0 = first channel by default.
In case of UV texture, this parameter should always be 0.
Reference to another Texture object of which we want to reuse the texture.
If we use this argument, we should not create any source on this texture and there is no need to refresh it either: the other Texture object will provide the texture for both materials/textures.

I am in version 2.66 and it's been a while since I try to replace as BGE, the texture of an object with that of another object, but it never works? Here is an excerpt of my script:

p1 = logic.getCurrentScene().objects['p1']
p2 = logic.getCurrentScene().objects['p2']
ID1 = texture.materialID(p1, "IM1.png")
ID2 = texture.materialID(p2, "IM2.png")
p2['p2'] = texture.Texture(p2, ID2)
p1['p1'] = texture.Texture(p1, ID1, 0, p2['p2'])

What to do please?

Post Reply