Quantcast Only works on a reload - WoWInterface
Thread Tools Display Modes
10-08-15, 04:05 PM   #1
chanceboon
A Murloc Raider
Join Date: Oct 2015
Posts: 5
Only works on a reload

This small sample of code is just a small experiment to pull the protrait. It works, but requires a reload of the ui...First load shows nothing, but it shows up if I reload the UI...

Lua Code:
  1. local myFrame = CreateFrame("Frame","Frame_Name",UIParent,"ButtonFrameTemplate")
  2.     myFrame:SetSize(255,200)
  3.     myFrame:ClearAllPoints()
  4.     myFrame:SetPoint("LEFT",75,75)
  5.     myFrame:EnableMouse(true)
  6.     myFrame:SetMovable(true)
  7.     myFrame:RegisterForDrag("LeftButton")
  8.     myFrame:SetScript("OnDragStart",myFrame.StartMoving)
  9.     myFrame:SetScript("OnDragStop",myFrame.StopMovingOrSizing)
  10.  
  11. local img1 = myFrame:CreateTexture(nil, "ARTWORK")
  12.     SetPortraitTexture(img1, "player")
  13.     img1:SetHeight(60)
  14.     img1:SetWidth(60)
  15.     img1:SetPoint("TOPLEFT", -6, 8)

I'm not at all sure...any ideas?
  Reply With Quote
10-08-15, 04:12 PM   #2
sticklord
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 57
I guess you mean it all works, but the SetPortraitTexture() doesn't add the player to the portrait on first startup? If so it might be because for some reason you can't get the texture at startup. Try to delay the creation abit i.e:

Code:
local ADDON_NAME, ns = ...
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self, event, ...)
    if (ADDON_NAME == ...) then
        -- Code here
    end
end)
Wait i changed my mind. Use this instead:
Lua Code:
  1. local myFrame = CreateFrame("Frame","Frame_Name",UIParent,"ButtonFrameTemplate")
  2. myFrame:SetSize(255,200)
  3. myFrame:ClearAllPoints()
  4. myFrame:SetPoint("LEFT",75,75)
  5. myFrame:EnableMouse(true)
  6. myFrame:SetMovable(true)
  7. myFrame:RegisterForDrag("LeftButton")
  8. myFrame:SetScript("OnDragStart",myFrame.StartMoving)
  9. myFrame:SetScript("OnDragStop",myFrame.StopMovingOrSizing)
  10. myFrame.unit = "player"
  11.  
  12. local img1 = myFrame:CreateTexture(nil, "ARTWORK")
  13. img1:SetHeight(60)
  14. img1:SetWidth(60)
  15. img1:SetPoint("TOPLEFT", -6, 8)
  16.  
  17. myFrame:RegisterEvent("UNIT_PORTRAIT_UPDATE")
  18. myFrame:SetScript('OnEvent', function(self, event, ...)
  19.     if (event == "UNIT_PORTRAIT_UPDATE") then
  20.         local unit = ...
  21.         if (unit == self.unit) then
  22.             SetPortraitTexture(img1, self.unit)
  23.         end
  24.     end
  25. end)

Last edited by sticklord : 10-08-15 at 04:21 PM.
  Reply With Quote
10-09-15, 04:26 AM   #3
chanceboon
A Murloc Raider
Join Date: Oct 2015
Posts: 5
That worked like a charm. Thank you so much!

...was drivin me crazy...
  Reply With Quote

WoWInterface » Developer Discussions » Graphics Help » Only works on a reload

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off