Hello
There a quite a few ways to achieve this in DBPro but I will explain the method that I usually implement.
You need to check if the MouseXY co-ordinates are contained within the 4 corners of the image.
So the required variables are Mouse [x,y] and Image [x1, y1] and [x2, y2]. Then check if x is within [x1, x2] and y is within [y1, y2].
Use MouseX() and MouseY() for mouse co-orindates.
As for the image co-ordinates, you set the image [x1, y1] when using Paste Image function. To get [x2, y2], add Image Width() to x1 and add Image Height() to y1.
e.g.
x1 = 100
y1 = 100
x2 = x1 + Image Width(imageNumber)
y2 = y1 + Image Height(imageNumber)
Paste Image imageNumber, x1, y1
You also have the option of using sprites and sprite collision commands but you are then limited to using only sprites, which is okay if you only use sprites.
I personally don't only use sprites so I use this function for Point in Rectangle checking.
Function PointIsInRect(chkX, chkY, x1, y1, x2, y2)
If (chkX > x1)
If (chkx < x2)
If (chky > y1)
If (chky < y2)
`Return TRUE - point is in the box
Exitfunction 1
Endif
Endif
Endif
Endif
`Return FALSE - point isn't in the box
Endfunction 0
Sorry, I have to go as I am having Sunday Dinner in a bit ..... but here's a little exercise.
Consider the following snippet and see if you can implement multiple boxes with it. That will give you an idea of how to region your image or use seperate images for a menu system.
Also note, arrays start at element zero so there are actually 5 maxBoxes
#Constant rgbRed 0xFFFF0000
#Constant rgbGreen 0xFF00FF00
#Constant rgbBlue 0xFF0000FF
Type udtBox
x1 As Integer
y1 As Integer
x2 As Integer
y2 As Integer
Endtype
Global maxBoxes
maxBoxes = 4
`There are 5 gBoxes (0 to 4)
Dim gBox(maxBoxes) As udtBox
Global midX
Global midY
Global Size
Global HalfSize
`****************************
Gosub initBoxes
Do
Cls
`Check mouse is in box
`If it is change colour and if mouse clicks in it change to another colour
If PointIsInRect(MouseX(), Mousey(), gBox(0).x1, gBox(0).y1, gBox(0).x2, gBox(0).y2)
If (MouseClick() <> 0)
Ink rgbGreen, 0
Else
Ink rgbBlue, 0
Endif
Else
Ink rgbRed, 0
Endif
Box gBox(0).x1, gBox(0).y1, gBox(0).x2, gBox(0).y2
Sync
Loop
End
`****************************
initBoxes:
midX = Screen Width() / 2
midY = Screen Height() / 2
Size = 50
HalfSize = Size / 2
gBox(0).x1 = midx - HalfSize
gBox(0).y1 = midy - HalfSize
gBox(0).x2 = gBox(0).x1 + Size
gBox(0).y2 = gBox(0).y1 + Size
Return
Function PointIsInRect(chkX, chkY, x1, y1, x2, y2)
If (chkX > x1)
If (chkx < x2)
If (chky > y1)
If (chky < y2)
`Return TRUE - point is in the box
Exitfunction 1
Endif
Endif
Endif
Endif
`Return FALSE - point isn't in the box
Endfunction 0
Must go my lift is in 20 minutes!
I'll be checking back later
All the best