Simple Solution Required , help :)
Author |
Message |
TheHobbit
|
Posted: Fri Jan 02, 2009 12:24 am Post subject: Simple Solution Required , help :) |
|
|
hey guys
so i've got a little problem, and i need a solution
im making a game where the user is going to be clicking 'icons' ( pictures ) to score points, after getting all my icons , mousevents nad other stuff working, i realized that its gona be super hard, because the only place the user clicks which the computer will recognize is the top corner
so, say i want the user to click anywhere on this square to score a point:
[]
the only reference point the program recognizes is the top corner. now, i COULD program so that if the user clicks any pixel within the area of the square it works, but that would be like, a 100 if statements.
can someone give me a simple solution as to how to go about this problem ? im thinking of somehow using getArea and such, but honestly im kind've stumped. any ideas would be helpful
thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Fri Jan 02, 2009 1:06 am Post subject: Re: Simple Solution Required , help :) |
|
|
TheHobbit @ Fri Jan 02, 2009 12:24 am wrote: i COULD program so that if the user clicks any pixel within the area of the square it works, but that would be like, a 100 if statements.
I'm glad that you've recognized that this sounds wrong (if you could imagine, some people actually go ahead with such "solutions").
Though I'm not sure what 100 if statements you could be thinking of. Can you describe, in any language of your choice (including English!) how you can know if a given point is inside a square? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
TheHobbit
|
Posted: Sat Jan 03, 2009 1:06 pm Post subject: Re: Simple Solution Required , help :) |
|
|
err
im thinking of figuring out the area of the square, say its a 5 x 5 square, so theres about 25 pixels inside of it.
( the ' 100 if statements' would be like, every one of those pixels, so it'd be 25 if statements in this case, which is still rather pointless )
OR
i could set some sort of a range from the origin ?
like er
( say origin is 0,0 , and the square is 5 pixels in length )
"if the 0 < xPos < 5 && if 0 < y < 5 , make click work" < math&english
in java if staments i could say
if ( mouseXPos <= 5 && mouseYPos <= 5 )
{
buttonPressed = true ;
}
gosh, would that work ?
im gona go try that out ! |
|
|
|
|
|
TheHobbit
|
Posted: Sat Jan 03, 2009 1:24 pm Post subject: Re: Simple Solution Required , help :) |
|
|
haha thanks but that one didnt work, i just tried
althought it might be that im placing it under the wrong mouseevent
any suggestions ?
i'll try other solutions meanwhile |
|
|
|
|
|
Tony
|
Posted: Sat Jan 03, 2009 4:07 pm Post subject: Re: Simple Solution Required , help :) |
|
|
TheHobbit @ Sat Jan 03, 2009 1:06 pm wrote:
( say origin is 0,0 , and the square is 5 pixels in length )
"if the 0 < xPos < 5 && if 0 < y < 5 , make click work" < math&english
You have the right idea. Now you just need to track down the problem in the implementation. In what way does this "not work"? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
TheHobbit
|
Posted: Sat Jan 03, 2009 10:46 pm Post subject: Re: Simple Solution Required , help :) |
|
|
im stoned.
it didn't work.
i mean, i figured it would, seeing as the maximum X and the max Y could be 5, thus any X or Y combination under or equal 5 should work.
okay, time to think .. gimme some time. |
|
|
|
|
|
TheHobbit
|
Posted: Sat Jan 03, 2009 11:34 pm Post subject: Re: Simple Solution Required , help :) |
|
|
OH. i think i might've figured it out
so
i set a range within my if statement, which made my statement very long, but working.
i made it so, if the mouseX is more than (iconXPos) but less than (iconXPos + iconLength)
if ((mouseXPos > iconPosx1 && mouseXPos < (iconPosx1+ iconLength)) && (mouseYPos > iconPosy1&& mouseYPos < (iconPosy1+ iconLength)))
^ thats the code, and it damn well works
if that's not what you wanted me to figure out ,enlighten me so i can make it more effecient !
but either ways , thanks a bunch tony ! |
|
|
|
|
|
Airjuggernaut
|
Posted: Sat Jan 03, 2009 11:34 pm Post subject: Re: Simple Solution Required , help :) |
|
|
TheHobbit is a genius :p
lol I'm his partner for this project, and he figured out what was wrong.
He got the basic game running, now we just gotta make it amazing
Thanks Tony! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
TheHobbit
|
Posted: Sun Jan 04, 2009 1:48 am Post subject: Re: Simple Solution Required , help :) |
|
|
oh ,for the love of god, it was juggernaut who figured out the mouseevents , so huzza for him !
anyhow
we're done here, thanks tony |
|
|
|
|
|
Insectoid
|
Posted: Sun Jan 04, 2009 11:02 am Post subject: RE:Simple Solution Required , help :) |
|
|
someone figured it out themselves, wonderful. You will go far if you choose to continue with CS after high school.
Just to piss you off, there are at least 5 tutorials on collision (which essentially is a button) on this site alone . But good job figuring it out! I applaud you! |
|
|
|
|
|
TheHobbit
|
Posted: Sun Jan 04, 2009 6:23 pm Post subject: Re: Simple Solution Required , help :) |
|
|
whaaa ! 5 tuts oh dear.
collision ?
no idea what that is.
haha, that wasn't too bad, i've got a buffering problem on my hands now, time to figure some more stuff out, sigh. |
|
|
|
|
|
Insectoid
|
Posted: Sun Jan 04, 2009 8:34 pm Post subject: RE:Simple Solution Required , help :) |
|
|
What you did was collision. Testing to see if the mouse was inside the box. The same concept is used to check if 2 boxes collide, or hit each other. Slightly different for ovals, but still the same concept. |
|
|
|
|
|
|
|