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 / selecting a 2D image with the mouse

Author
Message
Foz
16
Years of Service
User Offline
Joined: 18th Dec 2007
Location: California
Posted: 14th Jan 2008 03:58
Is there a method to detect a mouse click over a 2D image other than to maticulously compare the x and y of each click against the approximate area of the image?


Foz, I am.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 14th Jan 2008 05:55 Edited at: 14th Jan 2008 05:55
can you use sprites vs pasting images? if so, how about using Sprite Hit? check the attachment for a demo i whipped up for this.

Virtual Nomad
AMD XP 1800+ (~1.6 Ghz) / 1.5 GB RAM
ATI Radeon 8700LE 128 MB / Windows XP

Attachments

Login to view attachments
flashing snall
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 14th Jan 2008 06:20
use sprite colossion instead of sprite hit though... its cooler.


This is my WIP, not even ready for a WIP thread yet though.http://smallgroupproductions.com/
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Jan 2008 16:21
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 14th Jan 2008 23:35 Edited at: 14th Jan 2008 23:46
side-note:
Quote: "
use sprite colission instead of sprite hit
"


can you explain this, please? i've never understood why collision is better than hit, (sprite or object). has collision proven more accurate than hit? in the PickSprite example i made, i went back and replaced the checks and it seems to be identical (was hoping sprite collision would take into account the "z-bias" of the sprites that overlap and automatically pick the upper-most one, but it didn't. (i did reverse their priorities, tho, to get the result i wanted). and, i thought maybe it would ignore the transparent parts (i made circle sprites too to test), but it didn't care there either, so... ). does it handle scaled or stretched sprites better? i just don't see the difference, otherwise.

edit: i just read TDK's collision tutorial (#10). i get that the difference is initial hit vs objects overlapping. but, in the PickSprite routine, that doesn't apply because the sprites are not "moving", correct?

man, i gotta sit and read all those tutorials some day soon

Virtual Nomad
AMD XP 1800+ (~1.6 Ghz) / 1.5 GB RAM
ATI Radeon 8700LE 128 MB / Windows XP
Foz
16
Years of Service
User Offline
Joined: 18th Dec 2007
Location: California
Posted: 15th Jan 2008 21:13
TDK's #16 tutorial, method 3 - detecting a hit on a sprite of unknown location was exactly what I was looking for...very helpful. Funny, I was actually going to ask if collision could be used to detect a mouse hit, but for some reason it never occured to me to simply place a hidden version of the same image at the mouse pointer.

But it seems that you can only use that for one shape at a time. Can you hide multiple images at the mouse pointer like that and tell it wich image check?


Foz, I am.
Foz
16
Years of Service
User Offline
Joined: 18th Dec 2007
Location: California
Posted: 15th Jan 2008 21:47
Actually, that last question didn't make any sense after going over the tutorial again - disregard.


Foz, I am.

Login to post a reply

Server time is: 2024-11-25 10:56:09
Your offset time is: 2024-11-25 10:56:09