I’m trying to check if a gui is on screen or not,
I have had one idea though:
Check and see if all of the corners are on screen,
but I cannot figure out how to do this.
I just need any solution that will tell me if it’s on screen.
alright, so it seems as none of the solutions i’ve been given actually work…
so i basically just went with my original solution
which is to just get the corners and check if they are on screen,
which does not count for gui rotation,
which is why this topic is technically not finished, and why this post is not marked as solution
if anyone is interested, i was using it for my is object on screen function for RNMU,
which basically makes a 2d bounding box around the part (also a function i added),
then checks if the 2d bounding box is on screen
(which is the best solution that exists currently, though if anyone has a better solution, post it here)
local function IsOnScreen(GuiObject)
if (GuiObject.Position.Y.Scale >= 0 and GuiObject.Position.Y.Scale < 1 and GuiObject.Position.X.Scale >= 0 and GuiObject.Position.X.Scale < 1) then
return true
else
return false
end
end
There are 2 ways of detecting this depending on if your frame’s position is using Scale or Offset (Don’t use them both at the same time cause it will always print “It’s on screen”):
local Camera = workspace.CurrentCamera
local Frame = script.Parent
-- Scale --
if Frame.Position.X.Scale < 1 and Frame.Position.Y.Scale < 1 then
print("It's on screen")
else
print("Not on screen")
end
-- Offset --
if Frame.Position.X.Offset < Camera.ViewportSize.X and Frame.Position.Y.Offset < Camera.ViewportSize.Y then
print("It's on screen")
else
print("Not on screen")
end
Not sure what you mean, but depending if your frame’s position uses Scale or Offset you will need a different if statement. If you don’t want to create an if statement for every value just use an in pairs loop.
local Camera = workspace.CurrentCamera
local Frame = script.Parent
if Frame.Position.X.Offset == 0 and Frame.Position.Y.Offset == 0 and Frame.Position.X.Scale >= .1 and Frame.Position.Y.Scale >= .1 then
print("Using Scale")
elseif Frame.Position.X.Offset >= 1 and Frame.Position.Y.Offset >= 1 and Frame.Position.X.Scale == 0 and Frame.Position.Y.Scale == 0 then
print("Using Offset")
else
print("Using Offset and Scale")
end
local ScreenGui = script.Parent.Parent
local Frame = ScreenGui.Frame
Frame:GetPropertyChangedSignal("Visible"):Connect(function()
if Frame.Visible == true then
print("Gui is on screen")
end
end)
You can change a bit. I’m not sure where you putted GUI.
local obj = script.Parent.Frame
local ViewSize = workspace.Camera.ViewportSize -- ScreenSize
local abs_size, abs_pos = obj.AbsoluteSize, obj.AbsolutePosition
local x1,x2,y1,y2 = abs_pos.X > ViewSize.X,abs_pos.X+abs_size.X < 0,abs_pos.Y+abs_size.Y*.5 > ViewSize.Y,abs_pos.Y+abs_size.Y < 0
if x1 or x2 or y1 or y2 then
return false -- object isn't on screen
else
return true -- object is on screen
end
Okay, i’m just really confused by the use case here. I assume that if its off the screen you (your script) has put it there so why would you need to detect it.