I know this will seem pathetic to a lot of people but I thought it was useful so I’m putting this simple code up.
On games it is often desirable to have a graphical meter (spedometer, life bar, graphic of a shield, or graphic of man with increasing levels of injury, etc, etc)
This code snipplet will load in an egg-texture-cards animation. But instead of an animation this object will load in all of the frames of the animation and will treat the last frame as 100% and will treat the first frame as 0%. You then run an update on the object and it will load in the appropriate frame. That way you can have different images for different levels of your meter. You can make life bars, shield graphics, etc.
class GraphicMeter: #Creates a graphical meter from a Egg-texture-card animation. A percentage can be passed to the Meter which will then load up the appropriate frame. def __init__(self, model = None): self.model = loader.loadModel(model) if self.model is None: return self.frames = self.model.find('**/+SequenceNode').node().getNumFrames() self.model.setTransparency(TransparencyAttrib.MAlpha) def setScale(self, scale): self.model.setScale(scale) def reparentTo(self, parent): self.model.reparentTo(parent) def setPos(self,pos): self.model.setPos(pos) def update(self,percent): frame = (float(percent)/100) * self.frames self.model.find('**/+SequenceNode').node().pose(int(frame-1))