Basically if you have an FPS and you have crosshairs, if you run them through this wrapper module then it will render in the same place it used to on the screen.
The module can be found here: http://www.roblox.com/guifix-item?id=241599960
Basically all you need to do is instead of saying:
local frame1 = Gui.frame1
just say
local frame1=guifix.add(Gui.frame1)
And instead of
Instance.new("Frame",Parent)
just say
guifix.new("Frame",Parent)
--by AxisAngle
--[[
Documentation
when creating new gui elements, use the guifix.new(type,parent) method rather than Instance.new(type,parent) method
To add an existing element to this, use the guifix.add(element) function rather than using the element itself.
This wraps the gui in custom functions which allows you to edit gui elements exactly as you did before in the correct screenspace
Extra functions:
oldsize
oldpos
newsize
newpos
add
]]
local guifix do
guifix={}
local elements ={}
local added ={}
local metamethods ={}
local TweenSize
local TweenPosition
local TweenSizeAndPosition
local oldsize
local oldpos
local newsize
local newpos
local add
local setmetatable =setmetatable
local newinstance =Instance.new
local rtype =game.IsA
local getchildren =game.GetChildren
local ud2 =UDim2.new
local camera =game.Workspace.CurrentCamera
repeat wait() until camera.ViewportSize.y~=0
local fix =1/(1-36/camera.ViewportSize.y)
function guifix.new(...)
print(1)
return add(newinstance(...))
end
function add(element)
if not added[element] then
if rtype(element,"GuiObject") then
elements[#elements+1]=element
local object=setmetatable({
element=element;
TweenSize=TweenSize;
TweenPosition=TweenPosition;
TweenSizeAndPosition=TweenSizeAndPosition;
},metamethods)
added[element]=object
if rtype(element.Parent,"ScreenGui") then
element.Size=newsize(element.Size)
element.Position=newpos(element.Position)
end
return object
else
return element
end
else
return added[element]
end
end
function oldsize(size)
local x=size.X
local y=size.Y
return ud2(x.Scale,x.Offset,y.Scale/fix,y.Offset)
end
function oldpos(position)
local x=position.X
local y=position.Y
return ud2(x.Scale,x.Offset,y.Scale/fix,y.Offset+36)
end
function newsize(size)
local x=size.X
local y=size.Y
return ud2(x.Scale,x.Offset,fix*y.Scale,y.Offset)
end
function newpos(position)
local x=position.X
local y=position.Y
return ud2(x.Scale,x.Offset,fix*y.Scale,y.Offset-36)
end
function metamethods:__index(index)
local element=self.element
if rtype(element.Parent,"ScreenGui") then
if index=="Size" then
return oldsize(element.Size)
elseif index=="Position" then
return oldpos(element.Position)
elseif index=="TrueSize" then
return element.Size
elseif index=="TruePosition" then
return element.Position
end
end
return element[index]
end
function metamethods:__newindex(index,value)
local element=self.element
if rtype(element.Parent,"ScreenGui") then
if index=="Size" then
element.Size=newsize(value)
return
elseif index=="Position" then
element.Position=newpos(value)
return
elseif index=="TrueSize" then
element.Size=value
return
elseif index=="TruePosition" then
element.Position=value
return
end
end
element[index]=value
end
function TweenSize(self,endsize,...)
local element=self.element
if rtype(element.Parent,"ScreenGui") then
endsize=newsize(endsize)
end
return element:TweenSize(endsize,...)
end
function TweenPosition(self,endposition,...)
local element=self.element
if rtype(element.Parent,"ScreenGui") then
endposition=newpos(endposition)
end
return element:TweenPosition(endposition,...)
end
function TweenSizeAndPosition(self,endsize,endposition,...)
local element=self.element
if rtype(element.Parent,"ScreenGui") then
endsize=newsize(endsize)
endposition=newpos(endposition)
end
return element:TweenSizeAndPosition(endsize,endposition,...)
end
camera.Changed:connect(function(property)
if property=="ViewportSize" then
local newfix=1/(1-36/camera.ViewportSize.y)
local fixscale=newfix/fix
for i=1,#elements do
local element=elements[i]
local sx=element.Size.X
local sy=element.Size.Y
local px=element.Position.X
local py=element.Position.Y
element.Size=ud2(sx.Scale,sx.Offset,fixscale*sy.Scale,sy.Offset)
element.Position=ud2(px.Scale,px.Offset,fixscale*py.Scale,py.Offset)
end
fix=newfix
end
end)
guifix.oldsize =oldsize
guifix.oldpos =oldpos
guifix.newsize =newsize
guifix.newpos =newpos
guifix.add =add
end
return guifix