Another method for a GUI scan would be to completely skip the “mouse over” business, you would of course need to know python. I do not believe mouse-over should ever be used for a GUI considering on what it is and how many calculations it has to use. If your GUI doesn’t dynamically change with moving buttons you can just set up an array of RECT variables, then on mouse click see if the cursor lays in one of the RECTs and use that as selection. Personally I would think that most GUIs would work with this kind of system, The problems with this is for non-rectangular buttons. Though you can always use circles as well by using the distance formula, or for more complex ones you can use Point in Polygon algorithm. The Point in Polygon method would be more intensive but would still be faster than the Engine having to calculate it in 3 space.
Edit:
Just wrote an example piece of this code: (Not tested but the theory should work)
#each button holds
#[0] = type of button
#[1] = Button id
# for rectangles [0]==0
# [2] = top left x [3] = top left y
# [4] = bottom right x [5] = bottom right y
# for circles [0] == 1
# [2] = center x [3] = center y
# [4] = radius
#
#Below is an example of how the button array should be set up.
buttons = [[0,"square_one",0,10,10,10],[0,"square_two",0,20,10,20],[1,"circle_one",30,30,10]]
def getButton(x,y):
for i in buttons:
if i[0] == 0:
#it's a square button
if x > i[2] and x < i[4] and y > i[3] and y < i[5]:
return i[1]
elif i[0] == 1:
#it's a circular button
tempX = x-i[2]
tempY = y-i[3]
if sqrt(tempX*tempX+tempY*tempY) < i[4]:
return i[1]
else:
#it's an error
return "NULL"
return "NULL"
Note: The input would have to be centered around the center of the screen utilizing the below to get the mouse position reletive to the center of the screen.
width = bge.render.getWindowWidth()
height = bge.render.getWindowHeight()
controller.sensors[“MouseMovement”].position
and the buttons would have to be also setup on this kind of grid.
Some Errors that might occur:
You must line up the buttons up correctly with what you have set in the code. I would suggest having a function that reads in your button objects and adds where it will line up with the pixels on the screen. This kind of a function would also remove scaling error when resolution is changed.
It ends up being more work but this is a clean method that doesn’t rely on the engine to do work for you. At the end of the day your game will represent the work you put into it.