diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2011-07-06 11:26:04 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2011-07-06 11:26:04 +0400 |
commit | 2691c6a84f213c69d956816bec4a8ec225c394d8 (patch) | |
tree | 16d8afb6dce75b8ab5d2d2cab69007657f182c61 | |
parent | b9810ffdde07b81f0fa934ca45124413e15fa38b (diff) |
new example for bge.texture, a basic texture replacement
fresh simple and didactic example straight from my bge book, enjoy it ;)
video texture documentation online ... tears dropping.
-rw-r--r-- | doc/python_api/examples/bge.texture.1.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/doc/python_api/examples/bge.texture.1.py b/doc/python_api/examples/bge.texture.1.py new file mode 100644 index 00000000000..5b387c8659c --- /dev/null +++ b/doc/python_api/examples/bge.texture.1.py @@ -0,0 +1,38 @@ +""" +Texture replacement +++++++++++++++++++++++ +Example of how to replace a texture in game with an external image. +createTexture() and removeTexture() are to be called from a module Python +Controller. +""" +import bge +from bge import logic +from bge import texture + +def createTexture(cont): + """Create a new Dynamic Texture""" + object = cont.owner + + # get the reference pointer (ID) of the internal texture + ID = VT.materialID(obj, 'IMoriginal.png') + + # create a texture object + object_texture = texture.Texture(object, ID) + + # create a new source with an external image + url = logic.expandPath("//newtexture.jpg") + new_source = texture.ImageFFmpeg(url) + + # the texture has to be stored in a permanent Python object + logic.texture = object_texture + + # update/replace the texture + logic.texture.source = new_source + logic.texture.refresh(False) + +def removeTexture(cont): + """Delete the Dynamic Texture, reversing back the final to its original state.""" + try: + del logic.texture + except: + pass |