Quantcast WoWInterface - View Single Post - Newbie LUA help with fontstrings
View Single Post
02-08-20, 01:49 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,214
You're creating a new fontstring on top of previous ones each time the OnEvent function is called. Just create one and update its text.

Code:
local frame = CreateFrame("Button", "save-disk_frame", UIParent)
frame:SetWidth(120)
frame:SetHeight(32)
frame:SetToplevel(1)
frame:SetFrameStrata("HIGH")
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:RegisterForClicks("RightButtonUp")
frame:SetPoint("TOP", Minimap, "BOTTOM", -150, 20)
frame.Text = frame:CreateFontString("text", "OVERLAY", "GameFontNormal")
frame.Text:SetJustifyH("CENTER")
frame.Text:SetPoint("CENTER", 0, 0)
frame:SetBackdrop({
    bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
    edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
    edgeSize = 16,
    insets = {left = 4, right = 4, top = 4, bottom = 4},
})
frame:SetBackdropColor(0,0,0,0.6)
frame:SetBackdropBorderColor(1,0.8,0,0.8)  

frame:RegisterEvent("PLAYER_STOPPED_MOVING");
local function eventHandler(self, event, ...)
	local speed = GetUnitSpeed("player")
	if speed <= 6 then 
		self.Text:SetText("Walking")
	else
		self.Text:SetText("Running")
	end
end
frame:SetScript("OnEvent", eventHandler);
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-08-20 at 03:26 PM.
  Reply With Quote