Refresh the image of a texture in BGE in game ?

Hi everyone,

I’m not totally new to blender but i’m bad in Python.

I’m making a game and I need my character to be able to take photos in game and then show them in the menu in a gallery (or maybe somewhere else)

I’ve been able so far to take the picture when i hit C in game : it creates a screen1.png file.

I’ve created a plane; give it a texture of the screen1.png and I want to know how to actualise the texture in game so that when I’ll hit C again in my game, the newly created screen1.png replace the old one live in game. at the moment it is never replaced I have to reload the image manually.

I’m sure a small python script with an always sensor would do wonder but I can’t do it myself AT ALL lol.

Here is what I have understood so far :

i have to do something like import.bge get all the object controller texture and stuff…and then what please ?

If anyone could write me the few line I need to make this in game gallery work i would be soooo happy _

It’s my first post, I’m french sorry for the bad eng.

Hope you can help;)

I keep doing my research while hoping for answer, here is what i come up with so far (it’s my first script ever) :

###################### load an image

#import bge
import bge

get the name of the image

I’m using an image named screen1.png

imageName = “screen1.png”

get image path

Mona_Lisa.jpg is in same directory as saved blend

imagePath = bge.logic.expandPath(’//images/’ + imageName)

get current scene

scene = bge.logic.getCurrentScene()

get list of objects in scene

objList = scene.objects

get object named galleryscreen1

obj = objList[“galleryscreen1”]

get matID for the obj named galleryscreen1

I named the material gallerie1

matID = bge.texture.materialID(obj, “gallerie1”)

get the texture

tex = bge.texture.Texture(obj, matID)

get image used as the texture source

tex.source = bge.texture.ImageFFmpeg(imagePath)

save ImageFFmpeg texture as an object variable

obj[“Texture_ImageFFmpeg”] = tex

display the image


get the saved object variable

tex = obj[“Texture_ImageFFmpeg”]

the name of the new image to replace original image

imageName = “screen1.png”

get image path

imagePath = bge.logic.expandPath(’//images/’ + imageName)

reload the texture


update the texture


it is of course not working lol but I suppose it might help to see what kind of answer I am hoping for. Thanks for helping :slight_smile:

I’ve yet tested any code from the video texture but by manually reload, do you mean you use texture.refresh to update it or something else?

Please use [noparse]

[/noparse] tags when posting code.

The code above is mostly comment and blank lines. The BGE API comes with a working example.

If you do not want to code, you can use my Dynamic Texture.

waouh ^^ thanks for taking time for me.

First i didn’t knew for the code tags, I will use it from now on.

Second, when I say manually reload : I mean go to UV image editor, AltR.

For the code; I went on a tuto site and I have copy/paste stupidly all the lines that seems to be related to my issue, and I have change the comments so that it fits my files/textures names.

Your Dynamic Texture looks like OK for me, I have to try it first.

I will of course let you know, THANKS!!!


Ok dude, we don’t know each other, but believe me when I say I’m gratefull :smiley: Love you man.

It works wonder it’s perfect. I had to add a boolean that i toggle off when I use your script to actualise the image so that it does it only once and don’t show the old picture afterward. I’m sure there is an easiest way to stop the image to go back to it’s first state but anyway it works perfectly !


PS: Is it a completely free script that I can do whatever I want to do with ?

While i’m on the subject of my gallery.
How can I “multiply” the process.

actually i can take a picture and It shows up on a plane in game live.

What if i want to take another picture and display it on an other plane next to the first one ? of course I can add some game properties, copy the logic but then i would have to do it 50 time for 50 pictures and it would be a mess, showing up on too many planes, etc…

Is there a way to automate this process? thanks again for any advice / solution

Yes, it is free