Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Making a mouse click box (like in a menu)

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 13th Feb 2011 02:54
Done a bit of searching but cant seem to find anything just yet. I am looking for a way to be able to click on a portion of a screen. Not one point or a pixel but a box, like an invisible box.
So say i loaded a bitmap in that looked like a menu screen with a few drawn boxes listing menu options. How could i make that into a recognised area to click in.

I remember an old program i used to use back in the amiga days (though i never got much further than if statements with it, its not like i could make a game) i used to be able to load a picture, obtain the correct portion of the screen i wanted by drawing a visible box over and over again paintstakingly moving co-ordinates till it matched up with the box on the image, then i knew where to position a mouse box, then i draw an invisible mousebox (so it didnt ruin the image) which was ready for a "if click in mousebox 1 then goto something" sort of command.

How do you do it in DB?
CodemanV
19
Years of Service
User Offline
Joined: 25th Aug 2005
Location: South Wales Valleys, UK
Posted: 13th Feb 2011 13:26 Edited at: 13th Feb 2011 13:30
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.


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.



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



Must go my lift is in 20 minutes!

I'll be checking back later
All the best
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 13th Feb 2011 17:35
Thanks for the help.

As i was waiting for this to be posted i continued searching and searching and came across a wonderful little demo by that Dforemanuk guy which really helped me out and pretty much told me what i wanted. Hes got loads of other really good vid tutorials and i might just purchase the ones that arent free. Thanks!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Feb 2011 17:50 Edited at: 13th Feb 2011 17:51
The quick and dirty way is to just check if the mouse coordinates are equal to or higher than the upper left corner and less than or equal to the lower right corner of the area you want to click.

This makes a box as a reference but you can delete the box and it'll still work in the same area.



Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 13th Feb 2011 23:15
Yeah thats what i was looking for, didnt think of doing it the easy way, typical me
Thats a nice way for when i want to knock up a quick menu, ill bare that in mind. For when i have a bit of time ill use the button based one and make it all fancy!

Once again thanks folks for your valuable time.

Login to post a reply

Server time is: 2024-09-29 02:34:08
Your offset time is: 2024-09-29 02:34:08