Simple way of refreshing/auto updating a PNG texture in the game engine?

I’ve tried using various video texture scripts people have posted around, but most are for video files and not a single image. And I cannot get any of them to work. I have a png in the same folder as the blend file and this image will change a few times, and I need the texture in-game to refresh/update when the PNG does (instead of showing the original version for the entire game).

Maybe this can help you out

I did this to simulate dazzling effect, and I used a script to update an image with the screen capture, pretty much like you want it, but with a different aproach.

This file is quite old, so dunno if it works with the latest 2.7x or UPBGE but it might give you a hint :slight_smile:

The term you’re looking for is “sprite”. The idea is that you have multiple states all within the one image, and use Python to move the UV co-ordinates. They can be used for constant animations, such as a 2d character animation, but the same technique works for just changing between some images occasionally.

I’ve used them a lot for buttons. The image has 4 states (enabled, hover, depressed, disabled), and the UV co-ordinates are moved depending on how I want the button to look.

If you can’t find any resources to help you do it then ping me and I’ll dig up some code out of one of my projects.

Apparently I should wait until after my morning coffee to post; I totally misunderstood your intention. Loading images mid game is a pain in the arse. You will need to detect changes by prodding the file occasionally and checking if it’s changed somehow (maybe check the modified date, or file size).

This should get you started. It’s from Blender 2.59, so might need some updating:

from bge import texture

# get the reference pointer (ID) of the internal texture
ID = texture.materialID(own, 'IMno_img.png')

# create a texture object
object_texture = texture.Texture(own, ID)

# create a new source with an external image
url = "my_image.png"

new_source = texture.ImageFFmpeg(url)

# the texture has to be stored in a permanent Python object
GameLogic.texture = object_texture

# update/replace the texture
GameLogic.texture.source = new_source


Thank you, I should have realized this and a sprite are the same thing. I did solve this problem this morning, somewhat…and it seems to be working. Using a keypress, a screenshot is taken which becomes a texture that appears in front of the screen which fake-pauses the scene. I’m doing this instead of using the “suspend scene” actuator since I am limited to using only one scene for a specific, unrelated thing that can’t be paused. Thank you anyway, I will test this as well and see if it works.

Here’s the script I am using:

r2t26.blend (831.7 KB)

Based on the comments in the file, it sounds like you’d have an easier time by having the overlay scene always there and have that control the suspension of the main scene. You can have multiple cameras in the overlay scene and swap between them in order to show different interfaces, or just spawn/remove interface objects in it.

I would imagine that if ‘nothing’ was changing in the main scene, such that seeing a screenshot instead would go unnoticed, then it would be easier to pause the scene instead. I’m curious what else needs to continue to process from that scene and if you can move that logic elsewhere instead, or do it after the scene has resumed.