View Single Post
08-08-16, 01:09 AM   #1
Ravenevar
A Defias Bandit
Join Date: Aug 2016
Posts: 2
Same background for multiple frames?

Hi there,

I've been using the same code to place the same background on different frames in my UI. It works fine but I'd like to figure out a more efficient way.

For example, on my PlayerFrame (courtesy of LynMinimap) I might have the following code:

Code:
	local bg = CreateFrame('Frame', nil, PlayerFrame)
	bg:SetPoint('TOPLEFT', PlayerFrame, 0, -26)
	bg:SetPoint('BOTTOMRIGHT', PlayerFrame, 0, 26)
	bg:SetBackdrop({
		bgFile = [[Interface/Buttons/WHITE8X8]],
		tiled = false,
		insets = {left = -3, right = -2, top = -3, bottom = -3}
	})
	bg:SetBackdropColor(0, 0, 0, 1)
	bg:SetFrameLevel(0)
	
	local trans = CreateFrame('Frame', nil, PlayerFrame)
	trans:SetBackdrop({
			bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
			tiled = false,
			insets = {left = -6, right = -5, top = -6, bottom = -6}
	})
	trans:SetPoint('TOPLEFT', PlayerFrame, 0, -26)
	trans:SetPoint('BOTTOMRIGHT', PlayerFrame, 0, 26)
	trans:SetFrameLevel(0)
	trans:SetFrameStrata('BACKGROUND')
	trans:SetBackdropColor(0, 0, 0, 0.6)
Now I want to use this same background for my TargetFrame. Currently I have just copy/pasted the above code and replaced PlayerFrame with TargetFrame and it works, but now I have double the code. Is there a way I can do it more efficiently? Looking at other addons I have tried using "for _,frame in next" and "for index,value in ipairs" but I can't seem to make them work.

Any help is greatly appreciated!
  Reply With Quote