|
| 09 Aug 2016 06:21 PM |
The area in which the AbsolutePosition Y is being calculated is a bit off.
E.g I've got a frame 100x100, positioned at Y scale 0.5 and X scale 0.5. When my script tries to detect the presence of the frame using its absoluteposition, the mouse has to always be about 10-20 pixels higher than the actual border of the frame to register it's detection.
Meaning that it doesn't detect it as soon as the mouse is within its X and Y absolutes. X is fine though, Y is just off.
local function MouseOver(frame) --returns true/false if the mouse is over a frame. (Or any GUI object) local TopBound = frame.AbsolutePosition.Y local BottomBound = frame.AbsolutePosition.Y + (frame.AbsoluteSize.Y) local LeftBound = frame.AbsolutePosition.X local RightBound = frame.AbsolutePosition.X + frame.AbsoluteSize.X if MouseY > TopBound and MouseY < BottomBound and MouseX > LeftBound and MouseX < RightBound then return true end |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 06:22 PM |
| Why not just use the MouseEnter and MouseLeave events? |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 06:23 PM |
| My structuring doesn't allow for it. So I have to use a script. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 09 Aug 2016 06:27 PM |
GetGuiExtents = function(Gui) local SizeX, SizeY = Gui.AbsoluteSize.X, Gui.AbsoluteSize.Y local PositionX, PositionY = Gui.AbsolutePosition.X, Gui.AbsolutePosition.Y local ExtentX = PositionX + SizeX local ExtentY = PositionY + SizeY return {Position = {X = PositionX, Y = PositionY}, Size = {X = SizeX, Y = SizeY}, Extent = {X = ExtentX, Y = ExtentY}} end
GetPointInExtent = function(Extent, PointX, PointY) local PointX = type(PointX) == 'number' and PointX or Mouse.X local PointY = type(PointY) == 'number' and PointY or Mouse.Y local XOverlap = PointX >= Extent.Position.X and PointX <= Extent.Extent.X local YOverlap = PointY >= Extent.Position.Y and PointY <= Extent.Extent.Y return YOverlap and XOverlap end
local isMouseOver = GetPointInExtent(GuiExtents,X,Y)
if isMouseOver then
end
Credit: TickerOfTime
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 09 Aug 2016 06:28 PM |
and check this out:
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=195765412
|
|
|
| Report Abuse |
|
|