The code snippet that I posted earlier was only for clamping the x coordinate to the screen, nothing else. It has to be combined with the previously existed code to achieve result.
But now I see that you practically had the same code already, except you used hardcoded sizes, but idea was the same. The *only* mistake was that instead of using results of x and y variables when setting gui position, you used mouse.x, mouse.y again, thus all the calculations were lost.
The correct code might look something like:
Code: ags
But now I see that you practically had the same code already, except you used hardcoded sizes, but idea was the same. The *only* mistake was that instead of using results of x and y variables when setting gui position, you used mouse.x, mouse.y again, thus all the calculations were lost.
The correct code might look something like:
int x = mouse.x + 20;
int y = mouse.y + 20;
if (x < 0)
x = 0;
if (x + gGui9.Width > Screen.Width)
x = Screen.Width - gGui9.Width;
if (y < 0)
y = 0;
if (y + gGui9.Height > Screen.Height)
y = Screen.Height - gGui9.Height;
gGui9.SetPosition(x, y); // <---- notice how SetPosition is using previously calculated x and y