WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Texture Coordinates problem. (https://www.wowinterface.com/forums/showthread.php?t=58899)

Zax 08-21-21 05:42 AM

Texture Coordinates problem.
 
I'm trying to display a progress bar made with a texture file in a frame. The goal is to set the width of this texture according to a given parameter: let's say from 0 (no visible texture) to 1 (texture fills all the frame's width). At 0.5, the left side of the bar must be filled with the texture.

At this time, I have:
Lua Code:
  1. myFrame.texture:SetTexture(pathToMyTGAfile)
  2.         myFrame.texture:SetTexCoord(0, 0.5, 1, 0.5)
  3.         myFrame.texture:SetAlpha(1)
Whatever the values of SetTexCoord(), the texture fills all the frame's width. :(
The bar size is 100 (w) x 15 (h) px. The TGA file is 8 (w) x 16 (h) px.

I know it would be easier to create a child frame inside the "bar" frame, fill it with texture and then set the width of the child frame, but in my case, it will lead to others problem. So I would prefer to manage the texture coordinates... If it is possible.

Thank you.

Billtopia 08-21-21 12:16 PM

SetTexCoord sets a subsection of the texture file to show as the texture like the minimap pips are all in one file and they pull each pip out by its coordinates.

https://wowpedia.fandom.com/wiki/API_Texture_SetTexCoord
perhaps a statusbar would work better. You could use your texture for the fill, have a background or not, set colors, have it mouse interactable or not... and more

Billtopia 08-21-21 12:29 PM

something like this
 
lua Code:
  1. local statusbar = CreateFrame("StatusBar", nil, UIParent)
  2. statusbar:SetPoint("CENTER", UIParent, "CENTER", 0, -250)
  3. statusbar:SetStatusBarTexture("Path to your texture file")
  4. statusbar:GetStatusBarTexture():SetHorizTile(false)
  5. statusbar:GetStatusBarTexture():SetVertTile(false)
  6. statusbar:SetStatusBarColor(0, 1, 0)
  7.  
  8. statusbar:SetMinMaxValues(0, 100) -- 0 - 100 bar
  9. statusbar:SetValue(50) -- half full

Zax 08-22-21 01:32 AM

Though initially I didn't want to create another frame/object, your solution is fine (just added SetSize()).
Thank you Billtopia :)


All times are GMT -6. The time now is 02:04 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI