Just trying to make some things for a GUI and though id start by making a window, then make it transparent, then make it move around when clicked on in a certain place, and move round with it till you let go but its that part im having trouble with.
Ive done buttons before and made a mouse click box, but this is stumping me getting the right maths as its not a fixed x, y co-ordinate. Can anyone help?
Set Display mode 800, 600, 32
Sync On
Sync Rate 0
Global A As Integer
Global MenuX, MenuY, MOffsetX, MOffsetY As Integer
MenuX = 50 `Menu Positions
MenuY = 50
MOffsetX = 0 ` Menu Offsets for when grabbing the window it doesnt snap the top right back to the mouse position
MOffsetY = 0
Load Bitmap "Forest Background.bmp", 0
Load Image "Window.png", 2, 1
Sprite 1, MenuX, MenuY, 2
Set Sprite 1, 1, 1
Set Text Opaque
Do
A = 0
MenuHandle()
If A = 1
Set Cursor 0, 30
Print "Mouse Over Menu"
Else
Set Cursor 0, 30
Print " "
EndIf
Set Cursor 0,0
Print " "
Set Cursor 0,0
Print MouseX(), " , ", MouseY()
Print MenuX, " , ", MenuY
Sync
Loop
Function MenuHandle()
MOffSetX = MouseX() `+ MenuX
MOffsetY = MouseY() `+ MenuY
If MouseX() > MenuX AND MouseY() < MenuY + Sprite Height(1) AND MouseX() < MenuX + Sprite Width(1) AND MouseY() > MenuY AND MouseClick() = 1
Sprite 1, MOffsetX - MenuX , MOffsetY - MenuY , 2
A = 1
Endif
Endfunction
I tried an offset thing but that didnt work out so went back and tried smoe other stuff so there is alsorts in that above code thats more likely not necessary and lots missing that more likely is.
Images attached.
Edit: Ok i just thought of an easier way to do this so cleaned up the code by a lot and tried it but this too doesnt work. It doesnt seem happy about wether the mouse point is over the menu or not. Really cant fathom why setting the offset sprite at the mousex and y wouldnt work when then moving it, but it doesnt so i cant see whats going on exactly.
Set Display mode 800, 600, 32
Sync On
Sync Rate 0
Global A As Integer
Global MenuX, MenuY As Integer
MenuX = 50 `Menu Positions
MenuY = 50
Load Bitmap "Forest Background.bmp", 0
Load Image "Window.png", 2, 1
Sprite 1, MenuX, MenuY, 2
Set Sprite 1, 1, 1
Set Text Opaque
Do
A = 0
MenuHandle()
DebugText()
Sync
Loop
Function DebugText()
If A = 1
Set Cursor 0, 30
Print "Mouse Over Menu"
Else
Set Cursor 0, 30
Print " "
EndIf
Set Cursor 0,0
Print " "
Set Cursor 0,0
Print MouseX(), " , ", MouseY()
Print MenuX, " , ", MenuY
EndFunction
Function MenuHandle()
If MouseX() > MenuX AND MouseY() < MenuY + Sprite Height(1) AND MouseX() < MenuX + Sprite Width(1) AND MouseY() > MenuY AND MouseClick() = 1
Offset Sprite 1, MouseX(), MouseY()
Sprite 1, MouseX(),MouseY(), 2
A = 1
Endif
Endfunction