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.

DarkBASIC Discussion / mouse click Q?

Author
Message
t10dimensional
16
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 27th Mar 2009 02:57
how do you make it where when you click on a certain area(10x10)on the screen it does somthing.
just a random Q

im new at this
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Mar 2009 05:26
if mouseX()>X1 and mouseY()<X2 and Mousey()>Y1 and MOuseY()<Y2
If mouseclick
do somthing
endif
endif


kinda self explanatory

New Site! Check it out \/
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 27th Mar 2009 06:33
Quote: "if mouseX()>X1 and mouseY()<X2 and Mousey()>Y1 and MOuseY()<Y2"


Fail! J/K caleb.

Added a mouseY that should be mouseX

if mouseX()>X1 and mouseX()<X2 and Mousey()>Y1 and MOuseY()<Y2

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 27th Mar 2009 08:56
It's true that what ever works, works, but It's not good practice to check the mouse function multiple times, you can cause the return value to vary and such.

BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 27th Mar 2009 09:12
True, I remember reading somewhere that windows constantly updates, meaning that technically the mousex() and mousey() values could change in between references.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Mar 2009 15:49 Edited at: 27th Mar 2009 15:53
I like...

I like it because it detects how far away the cursor is from a specified point (the middle of the square) and compares that to how wide/high the square is. Rather than checking minimums and maximums for both axis.
(what is the plural of axis?)

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Mar 2009 18:23
dang i always type y instead of x that is a common problem for my programs i don't know why though lol


Hm didn't think about them changing. nice catch ashinga!

Obese:

not sure what abs does.

this might be very simple but i'm tired. your checking the distance between mousex and the center of the square and if that is less then the distance between the middle and the side of the square then your in it. is that what your doing?

New Site! Check it out \/
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 27th Mar 2009 19:17 Edited at: 27th Mar 2009 19:17
ABS turns a value into a positive.


The outcome is a positive 10, this is great for finding the difference between 2 numbers.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Mar 2009 19:27
oh ok gotcha thanks!

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 27th Mar 2009 23:39
obese, i think its also axis, just pronounced aks-EEZ (I feel like webster)
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 27th Mar 2009 23:44 Edited at: 27th Mar 2009 23:44
Spelled axes, pronounced "ax-ees."

BTW, ABS(x) takes the absolute value of x, which is it's distance from zero, so it's always a positive.

~QJ
That's what they WANT you to think...
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 27th Mar 2009 23:48
o, ur right, nice call
Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 29th Mar 2009 11:03
for some reason I feel the need to post some good example code here.
suppose you have set the video display to say 1024x768 and have your buttons all neatly setup in a vertical pattern with the top botton located at a x position of 400 and a y position at around 100
and each button has a 10 pixel distance between them :


good luck

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 29th Mar 2009 18:01
that would work, although i usually put it into a function that returns 0 or 1

note though that the only reason he has all the y possibilities inside the x check is because they all share the same x, just wanted to make that stated b4 some1 tried it and posted here about how it didnt work
Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 31st Mar 2009 18:42
very well said that1smartguy. you are totally correct. This cuts down on the messyness of the code quite a bit but, there are still those wonderful occassions where you will have to check x/y seperately for each button especially when the buttons are not neatly lined up or are scattered across the screen at varying x/y positions.

bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Apr 2009 05:55 Edited at: 1st Apr 2009 05:56
I don't think you need two mousey()'s
if mousey()>100 and mousey()<140
I'm not sure if this is more efficient but it bugs me seeing the same thing twice
if ABS(mousey() - (100+140)/2) < (140-100)

[edit]
ironically I've already suggested that method x-(

can't read?
Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 1st Apr 2009 18:56
some math routines are slow so you may have to watch that but have hit on something I failed to see ->it may actually be a lot faster to check for a mouseclick and then the x/y values at the cost of nesting a little deeper rather than constantly checking for the x/y values before the click
I dont know why I didn't think of this before as it may have cut down on a lot of proccessing. here is the revised code and thank you obese for bring that up again :



bluestar4~
---Missle Might - Hero Battles - Zillipede --- which do you like the best ?

Login to post a reply

Server time is: 2025-08-08 20:42:31
Your offset time is: 2025-08-08 20:42:31