Animated Textures Tutorial Solved

Hi guys, i had the same problem about animating textures on real time, and i decided to share how i resolved the situation.

First the video texture:

We will need a jpg file with sequencial images in it.
lets say we have 10 frames of 320x240 then we will need to create an image canvas size of 3200x240 and put each frame side by side.

for example:

this image is 1600x300= 4 frames * 400 each x height (300)

Setup the scene:

Well start blender, delete the default cube and add a plane
Split an uv image editor window
With plane selected enter edit mode, press U, Reset (we got our uvs)
Open the image file at uv image editor.
The uvs should cover all the image so we need to stretch to 400 px
Well, select the right most uvs, press G, X, -1200 (4 images x 400 px width)
Exit edit mode now.
We should see the first frame on the plane.

The gamelogic

Press F4 and lets logic.

Select the plane.
Lets create some properties we will need
1.- The timer. click the big “Add property” buttom, name it “now” (without quotes) :stuck_out_tongue: ,change the type float to timer and click D for debug.
2.-Add an int and name it “frame”, click “D” for debug too.
3.-Add an int and name it “curframe”
4.-Add a float, name it “imgwidth” with value 400
5.-Add a float, name it “videolg” with value 1600

We will need some python scripting so dont panic, its very simple.
Create a text script (Text Editor window) and name it “animtex” for example

Once we have our text file created. with the plane selected lets add an Always sensor with pulse mode true (this is the first “” buttom) attached to a python controller
associated to our “animtex” script

Now lets write the script:

#here we are retrieving the controller(cont), the plane(obj), and the property "frame"
#inside the plane

cont = GameLogic.getCurrentController()
obj = cont.getOwner()

#we can change fps value to set the time speed 

obj.frame = int(*fps)

#here when "frame" changes, we retrieve the plane´s mesh(me), inside the mesh
#we retrieve the materials(mats), inside the materials we retrieve the vertexs(vertex)
#inside the vertex we retrieve the uvs (uv). 

if obj.frame!=obj.curframe:
        me = obj.getMesh()
        for mats in range(me.getNumMaterials()):
            for vtx in range(me.getVertexArrayLength(mats)):
                vertex = me.getVertex(mats,vtx)
                uv = vertex.getUV()

#once we got the uvs we can play with them
#in this case each time obj.frame changes, we translate the uvs on x axis(uv[0]) 

this is the blend file.

Hope that helps.

animated textures work well for me?!
And it’s better, maybe, that your textures follow the “power of two” rule, ex. 1024x1024, 1024X2048, 512X1024 and so on!

Nice point otto thanks.
I had strange behaviours using realtime properties. When i exit BGE Preview mode, realtime properties is reset to 0 dont know why.

I thought it could be interesting to show how to move uvs on a texture, it is much more functional and you can do a lot of things like scrolling a texture and so on.

click on the blog in my signature. I’ve written a tutorial a long time ago, lol.

Hey Killer how did u do blur? i cant see any script around.