Aligning OnscreenImages

So I want to have an OnscreenImage (a bar) aligned to the left, such that when I scale down the image, the left side will stay put, but the right side will “pull in”, making it appear to grow smaller. However, given that images seem to have their origing point at their center, doing this requires calculations, which I don’t want my program to do every frame (which is how I have to update the bar). Is there a simple way to do this?

Can you try to parent the image to a2dLeftCenter (or a2dTopLeft or a2dBottomLeft)?

Unfortunately, the image needs to be parented to another image; both images are also billboards floating around in the game world, and not a part of the GUI. The changing bar’s parent is, in turn, an actor, which is reparented to render; the bar itself is created within a class inheriting from DirectObject.

I tried what you suggested, but I got a “global name a2dLeftCenter not defined” when using it alone (since it’s an attribute of ShowBase, and my class is DirectObject, I guess this makes sense), and I found it couldn’t be used as an attribute of the parent image. Thanks for the suggestion, though - I could make use of a2dLeftCenter some other time.

  1. align the image to itself to the right so its origin is at the left
  2. call flattenLight() to freeze transform

to help you align the image :
[DirectGUI or nodepath alignment)