Transparency on DirectWaitBar textures

I’m making a health bar for the game I’m working on. I followed the directions given in DirectGUI (DirectWaitBar)… to put textures for the background and fill.

My problem is that I want the bar to have a non-rectangular shape. I can set transparency on the background texture (I just called setTransparency on the health bar object). I can’t figure out what to call setTransparency on to get the fill to have transparency as well. (barStyle apparently does not have a setTransparency method)

        self.healthBack = loader.loadTexture("gui_textures/healthbar_vert_sick.png")
        self.healthFore = loader.loadTexture("gui_textures/healthbar_vert_healthy.png")

        self.healthBar = DirectWaitBar(frameSize = (0, 1, 0, 1),
                                       scale = (1, 1, 0.1),
                                       pos = Vec3(-1, 0, -0.95),
                                       relief = DGG.FLAT,
                                       frameColor = (1, 1, 1, 1),
                                       frameTexture = self.healthBack,
                                       barRelief = DGG.FLAT,
                                       barColor = (1,1,1,1)
                                      )
        self.healthBar.setTransparency(TransparencyAttrib.MAlpha)

        self.healthBar.barStyle.setTexture(self.healthFore)
        self.healthBar.updateBarStyle()

        self.healthBar.setName("healthbar")

        ts = TextureStage.getDefault()
        self.healthBar.setTexGen(ts, TexGenAttrib.MWorldPosition)
        self.healthBar.setTexProjector(ts, render2d, self.healthBar)
        self.healthBar.setTexTransform(ts, TransformState.makeHpr(VBase3(0, 90, 0)))

        self.healthBar.setPos(-1.2, 0, -0.2)
        self.healthBar.setR(-90)

-Selene

Setting transparency on the healthBar should also serve to apply transparency to the background (since a child inherits the state of its parent). In fact, in my quick experiment, that works fine for me. The background texture also shows transparency.

David

Er, the background does show transparency, my problem is transparency for the foreground.

You can see that there’s transparency at the top of the bar, which is the background image, but not at the bottom, which is the “fill” (barStyle) image. (please excuse the programmer art)

-Selene

Er, sorry. Yes. I get transparency on the foreground too. It shows through to the background texture. If you’re not seeing the background through the foreground bar, are you sure that your foreground texture has an alpha channel?

David

Hrm, I could have sworn I saved it with an alpha channel, but apparently I didn’t.

It works now. Thanks!

-Selene

I got new textures for the health bar, but now the texture seems to be wrapping oddly around the frame.

I’m using this code to put a foreground texture for the bar fill:

        self.healthBar.barStyle.setTexture(self.healthFore)
        self.healthBar.updateBarStyle()
        self.healthBar.setName("healthbar")

        ts = TextureStage.getDefault()
        self.healthBar.setTexGen(ts, TexGenAttrib.MWorldPosition)
        self.healthBar.setTexProjector(ts, render2d, self.healthBar)
        self.healthBar.setTexTransform(ts, TransformState.makeHpr(VBase3(0, 90, 0)))

The result is:

If I comment out the lines starting with ts = TextureStage.getDefault(), it looks like this:

(The second image is mostly so you can see what the textures actually look like.)

This code used to give me a proper filling health bar. Did I mess something up? (I did change frameSize and pos as well as frameTexture when I put in the new texture.)

-Selene

The setTexProjector call will generate UV’s that basically stick the texture to the glass–so that if you move the bar around (by changing frameSize or framePos) it will leave the texture behind.

Your two options are (1) don’t use the setTexProjector, and let the texture naturally stretch to fill the size of the bar, or (2) continue to use setTexProjector, but adjust the tex transform to match the change you applied to the frame. I’d recommend using setTexOffset, setTexScale, and setTexRotate in lieu of the more awkward setTexTransform.

David