Sprite animation within BGE.

Hello everyone,

I’ve been bending my brain trying to figure this out. :slight_smile: UV animation of sprite sheets, with each generated object able to carry on it’s own specific or “random” sprite. I have the UV changing down within python, where I can pass the UV point for the bottom left corner of my plane UV map and have the script move that around.

The “problem” that I have is everything in Blender is working as designed. :smiley: From what I’ve been able to gather, the UV can only be defined in the material. And changing that UV changes it for every other object referencing that material.

I’ve seen other scripts here where they’ve gotten around that somewhat by mesh-swapping within the called object, but I’m unsure of how that will play with performance in the game engine (still learning about the scenegraph and performance issues as well). I’m trying to not have to create extra objects that might not be necessary.

I’ve seen the play-straight-through UV tile mapping in the UV settings, but I wasn’t able to find any information on how to control that through python in the API docs.

If anyone has any guidance or resources to point me towards on how to move this forward, or even any documentation on the scenegraph, that would be fantastic!

Much thanks!


@MisteR2 - Yo! So, as you’ve figured out, altering the UV values via Python changes them for all objects that share the same mesh. That means that if any object shares the same mesh as another in the Blender scene, or if you add an object in-game, they’ll share meshes (i.e. all spawned instances of the Explosion object share the same mesh, so animating one animates them all).

This can be bad, since if you have objects that are created at different times (like an explosion), then it won’t animate correctly (each one that is spawned will try to animate the same sprite, or the animation might reset each time you spawn a new one). The upside of this is that you can have multiple objects that can share animations without having logic on all of them (i.e. background torches in a scene).

The method that I use for most unique game objects (like NPCs, the player, or explosions) is what you mentioned, which is mesh-swapping. By swapping meshes, several objects can share frames of an animation, but the mesh itself isn’t being altered. In my experience, it’s not very hard on the logic at all. I made a Python module for sprites, and it allows both methods of animation. You can find it here.

Hey SolarLune, thanks for the reply! I’ll give your module a shot and see if it fits the bill for what I’m doing ( it probably will :smiley: ). I’ll post my project back up here once it’s done.

Supermoaaa, thanks for the links, but I already have the sprite sheets covered. :slight_smile: