SetTexCoord help

UI and Macro
Hi, I have a status bar whose texture I would like to cut in half, preserving the right side, but keeping the right side anchored to the right side of a background texture I have, similar to a reverse filling of a status bar. However, no matter what attempts I make, it always takes the right side of the image and stretches it over the left side, or moves it around. Any ideas?
We'd need to see the code. A simple example is:
local f=CreateFrame("Frame","TcT",UIParent)
f.value = 0
self.value = (self.value + 1)%100
local width = (100-self.value)/100

Is an image of what I have already coded. The frame on the left is finished, as a status bar that operates under the unit health event with a plaer conditional. The one on the right is giving me problems. See how the angle on the right side of the frame is squished, while the background texture isnt? I've been looking for a way to just shear off a percentage of the overlay frame while preserving that angle. Is that possible?

My initial code for editing the frame goes something like:

/script stat_texture:SetTexCoord(percent, 1, 0, 1)
/script stat_texture:SetWidth(percent*background_texture:getWidth())

and when the percentage is o.3, it gives the picture linked above.

edit: Figured it out (i think).

/script stat_texture:SetTexCoord(percent, 1, 0, 1)
/script stat_texture:SetWidth(1-percent*background_texture:getWidth())
Careful of order of operation:

If percent is .75 and width is 100

(1-percent)*background_texture:getWidth() = 25

1-percent*background_texture:getWidth() = -74
make that Stat_Texture:SetTexCoord((1-percent), 1, 0, 1)
target_arrow:SetPoint("BOTTOM", Stat_Texture, "TOPLEFT", 10/250*Stat_Texture:GetWidth(), -5)

But when I do that, I use these input values, and get this result- it's rather confusing.
Imagine your health dips to 90%, or 0.9. In that case, the left coordinate should move back by a factor of 0.1, and the width should be 0.9* whatever the original width was.
It appears as if my width of my textures are actually larger than what they appear, and the extra part is not showing...the arrow is anchored to the end of my overlay texture (grey) and when it's resting at 0, 0 in the upper left hand corner it extends 40 pixels out, I have to set its point in 40 to make it line up.
Here's the code I've been running on, the XML initializes most of the frames, and the scripts give them their attributes, so the XML is not really needed.
Fixed: It was the textures themselves. Chunk of canvas space in the .tga, didn't see them until I opened them.

Join the Conversation

Return to Forum