Animations / Videos on GUI


is there a way to use animations (.gif) or videos on a gui?

For example, in my pre-lobby loading screen, i would like to have a rotating loading icon. How can i do that?


there are some ways you can do that. I’m not quite sure if gif files are supported, but video files in general are loaded through FFMPEG, so it might be.

To load an animation/video file you’ll simply load it as a texture and apply it on a frame or whatever GUI widget you want to use. E.g.:

from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectFrame import DirectFrame

from panda3d.core import loadPrcFileData
# Make sure textures-power-2 is set to none
# otherwise you'll get a black border around your video 
loadPrcFileData("", "textures-power-2 none")

app = ShowBase()

myMovieTexture = app.loader.loadTexture("path/to/my/movie.ogv")
myFrame = DirectFrame(image=myMovieTexture)

Further details can be found here in the Manual:

Alternatively you can also convert your video to an egg file and load that instead. The steps to do so are described in this manual section:

hi there,
i tried your code but the video was not playing in full screen mode, leaving grey bands on the sides.

So instead, i tried to figure out the code provided in the panda3d example progam:

self.tex = MovieTexture("name")
success ="Assets/4k/Videos/intro2.mp4")
assert success, "Failed to load video!"
# Set up a fullscreen card to set the video texture on.
cm = CardMaker("My Fullscreen Card")
# Tell the CardMaker to create texture coordinates that take into
# account the padding region of the texture.
# Now place the card in the scene graph and apply the texture to it.
card = NodePath(cm.generate())
self.sound = base.loader.loadSfx("Assets/4k/Videos/intro2.mp4")
# Synchronize the video to the sound.

but here i have two problems:

the video plays in loop, and i don’t see an obvious way to stop it from the documentation;
my video contains only a short bit of audio in the middle, but if i try to run the code with the last two lines (self.sound = base.loader... and so on) the video doesn’t play, it is stuck in its first frame.

Thanks, Tom.


Panda3Ds default is to loop media. You can simply set that with a call of self.sound.setLoop(False)

As for the video not playing, did you call in your actual code? Since, it’s not in the lines you posted here. Otherwise it will only get loaded and displayed, not started. Also, just to make sure you didn’t miss this detail, you will control the video via the audio file once it’s synchronized to it.