I’m trying to add simple healthbars to my chars,
What i’m doing now is loading 2 images (healthframe and the healthbar) images into a DirectGui frame and attaching them to the correct chars.
Everything is working quite ok, the only problem is it seems impossible to position & scale the actual bar correctly so it fits decently into the frame
I can get the full bar sort of positioned correctly (using very ugly floats) but when I scale it (when health decreases) the scaling origin is in the middle of the image, I tried specifiing a frameSize manually to correct it but that didn’t seem to affact anything. and calculating the correct position offset for the bar isn’t working out either
anyone has a fix / better way to do this … I guess i’m not the first one to make healthbars in panda
here is my current code:
# in init self.healtFrame=DirectFrame(relief=None, image="media/health_bar_empty.png", image_scale=(4,1,0.5)) self.healtFrame.setPos(0, 0, 12) self.healtFrame.setBillboardPointEye() self.healtFrame.reparentTo(self.spiderActor) self.healtBar=DirectFrame(relief=None, image="media/health_bar.png", image_scale=(4,1,0.5)) self.healtBar['image_pos'] = (0.1995, 0, 0) self.healtBar.setBillboardPointEye() self.healtBar.reparentTo(self.healtFrame) # in updatetask: self.healtBar['image_scale'] = (4 * self.health / 100.0, 1, 0.5) self.healtBar['image_pos'] = (0.1995 - 4 * self.health / 200.0), 0, 0)