-
Posted by corunir on Tue, 05 Apr 2011 11:11:28
Hello, I am having some difficulties with showing a FontString in my frame. What I am trying to accomplish is showing text over statusbars, but that will be the next step, since I cant even get the text to be shown in my frame. Here is the code, so can someobody be kind enough to point me at what am I doing wrong.
f = CreateFrame("Frame",nil,UIParent) f:SetFrameStrata("BACKGROUND") f:SetWidth(208) f:SetHeight(112) t = f:CreateTexture(nil,"BACKGROUND") t:SetTexture(0, 0, 0, 0.5) t:SetAllPoints(f) f.texture = t f:SetPoint("CENTER",200,200) f:Show() frameText = f:CreateFontString("ime","HIGHLIGHT","GameFontNormalSmall") frameText:SetText("text") frameText:SetTextHeight(20) frameText:SetTextColor(1,1,1,1) frameText:Show()
Result of this code is a half-transparent rectangle adjusted for 200,200 from the center of my screen.
-
Posted by jnwhiteh on Tue, 05 Apr 2011 13:25:53
You don't ever anchor the font string anywhere, therefore WoW has absolutely no idea where to put it, what size it should be, etc. Give it an anchor, or :SetAllPoints(true).
-
Posted by corunir on Tue, 05 Apr 2011 13:43:05
Thanks for the reply, but either I don't understand the way anchoring works, or I am blindly doing something wrong. I added
frameText:SetAllPoints("f")
before the frameText:Show(), , tried it with "UIParent" and true as an argument, im pretty much guessing what to do.
I also tried with frameText:SetPoint("CENTER","f","TOPRIGHT",0,0).
-
Posted by jnwhiteh on Tue, 05 Apr 2011 13:57:26
Thanks for the reply, but either I don't understand the way anchoring works, or I am blindly doing something wrong. I added
frameText:SetAllPoints("f")
before the frameText:Show(), , tried it with "UIParent" and true as an argument, im pretty much guessing what to do.
frameText:SetAllPoints(true)
That's all you need to do, because
frameText
is already parented to your frame.I also tried with frameText:SetPoint("CENTER","f","TOPRIGHT",0,0).
That just sets one anchor point, that doesn't guarantee it has a placement. Also, you should not use "f", you should just use
f
. Don't rely on 'names' to use the API.frameText:SetPoint("TOPLEFT", f, "TOPLEFT", 0, 0) frameText:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", 0, 0)
That would make the font string the same size as 'f', since it would be anchored in the top left and bottom right.
It would be useful for you to re-read Chapter 9, as it covers this quite well.
-
Posted by corunir on Tue, 05 Apr 2011 14:12:06
I know it sounds desparate, but I tried probably every possible combination of qouted names, non-quoted, even c/p some code which should do exactly what I need but still no text is appearing, so could it be something else? I tried both examples you typed and none of them makes the text appear. All I am getting is an empty half-transparent rectangle. Layers seem fine, since text is on highlighted and rectangle on a lower level. I have to admit I still didn't buy the book since I found it too late and I am on a bit of a deadline soon (this is actually a university project for tracking player behaviour and showing it recount/skada style+logging logging everything in chatlog using some chat filtering), but I will probably have to completely rewrite it in a month or two and then I will have enough time to read the book cover to cover. And I dont want to get the book the illegal way, since I appreciate the hard work you do over here.
I successfuly created statusbars that respond to events and are responding correctly to events. They are anchored inside of the frame f with following code (one of six
self.PvPStatusBar = CreateFrame("StatusBar", nil, f) self.PvPStatusBar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar") self.PvPStatusBar:GetStatusBarTexture():SetHorizTile(false) self.PvPStatusBar:SetMinMaxValues(0, 100) self.PvPStatusBar:SetValue(teston:GetPercentage("PvP")) self.PvPStatusBar:SetWidth(200) self.PvPStatusBar:SetHeight(14) self.PvPStatusBar:SetPoint("TOPLEFT",4,-94) self.PvPStatusBar:SetStatusBarColor(0,1,0) self.PvPStatusBar:SetScript("OnUpdate",function() self.PvPStatusBar:SetValue(teston:GetPercentage("PvP"))end)``
but they are commented out at the moment. Is there a way I can put text directly on top of the bar? I am guessing something like this would do the trick, but nothing shows up, again.
frameText = self.PvPStatusBar:CreateFontString("ime","HIGHLIGHT","GameFontNormalSmall") frameText:SetText("looooong text") frameText:SetTextHeight(20) frameText:SetTextColor(1,1,1,1) frameText:SetAllPoints(true) frameText:Show()
-
Posted by jnwhiteh on Tue, 05 Apr 2011 14:25:10
The problem is pretty simple. You've put the font string in the HIGHLIGHT layer. This layer is only visible when the mouse is over the frame. Since the mouse is not enabled for mouse events, this can never happen. Try this:
YourFrame:EnableMouse(true)
And you'll see that this is the case. The text should go in the OVERLAY layer, most likely.
-
Posted by jnwhiteh on Tue, 05 Apr 2011 14:26:34
Please don't edit posts. It's incredibly confusing, especially when you don't say what you've added or edited. It is also confusing to people who come and read the solution after the fact, because the posts have changed.
I successfuly created statusbars that respond to events and are responding correctly to events. They are anchored inside of the frame f with following code (one of six bars):
self.PvPStatusBar = CreateFrame("StatusBar", nil, f) self.PvPStatusBar:SetStatusBarTexture("Interface\TargetingFrame\UI-StatusBar") self.PvPStatusBar:GetStatusBarTexture():SetHorizTile(false) self.PvPStatusBar:SetMinMaxValues(0, 100) self.PvPStatusBar:SetValue(teston:GetPercentage("PvP")) self.PvPStatusBar:SetWidth(200) self.PvPStatusBar:SetHeight(14) self.PvPStatusBar:SetPoint("TOPLEFT",4,-94) self.PvPStatusBar:SetStatusBarColor(0,1,0) self.PvPStatusBar:SetScript("OnUpdate",function() self.PvPStatusBar:SetValue(teston:GetPercentage("PvP"))end)``
but they are commented out at the moment. Is there a way I can put text directly on top of the bar?
Yes, you just create font strings.. I don't understand the question..
-
Posted by jnwhiteh on Tue, 05 Apr 2011 14:29:27
STOP EDITING. Just stop.
-
Posted by corunir on Tue, 05 Apr 2011 14:30:06
Thank you, layer was the problem. Sorry about the editing, most forums prefer editing rather than double posting. Expect a book purchase very soon :D.