gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Detecting stylus to text/sprite collision

#151603 - putzpie - Sat Mar 01, 2008 4:26 am

How do you detect whether or not text (or a sprite for that matter) has been touched by the stylus? It is possible right? I used the search function but didn't find anything on it. Is it possible with text? Any example code? etc, etc.
Thank you in advanced!
_________________
http://putzpie.com

#151604 - tepples - Sat Mar 01, 2008 5:27 am

putzpie wrote:
How do you detect whether or not text (or a sprite for that matter) has been touched by the stylus?

Do you know where the text or sprite was drawn? How big is it?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#151605 - putzpie - Sat Mar 01, 2008 5:37 am

tepples wrote:
putzpie wrote:
How do you detect whether or not text (or a sprite for that matter) has been touched by the stylus?

Do you know where the text or sprite was drawn? How big is it?


It's about 30x5 and yes I know where it's drawn, but I meant is there a way to see if the text has been touched without having to specify a box around it? like instead of having to make a box and see if it's been touched. Is that possible or not?
_________________
http://putzpie.com

#151606 - tepples - Sat Mar 01, 2008 5:52 am

putzpie wrote:
It's about 30x5 and yes I know where it's drawn, but I meant is there a way to see if the text has been touched without having to specify a box around it? like instead of having to make a box and see if it's been touched. Is that possible or not?

Are you asking whether there's some sort of hardware support for picking?

When you test for hits, you usually test whether a point is within a geometric shape. In this case, the shape would be the box that contains the text. You loop from front to back over all the shapes that the user can touch, and then you return the first object that the touch point is within.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#151621 - putzpie - Sat Mar 01, 2008 5:24 pm

Yes I know you could do that but I should've restated my question to is there a way to check if an object has been touched without checking and making a box around it, or no? Is that possible? Maybe I'm just asking the question wrong, but I think I have an answer now.
_________________
http://putzpie.com

#151626 - tepples - Sat Mar 01, 2008 5:53 pm

putzpie wrote:
Yes I know you could do that but I should've restated my question to is there a way to check if an object has been touched without checking and making a box around it, or no? Is that possible?

I can answer your question more definitively if you tell me how you define "an object" and "to touch an object".
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#151628 - putzpie - Sat Mar 01, 2008 6:21 pm

I wish I knew how to explain it better. what I mean by an object would be like, say some text, and then when you touch it, is there a way to check *without* checking if the stylus touched in that general location. Like let's say instead of making a box to detect if it's been touched around it, instead is there some kind of way to see if it's touched? I think that I already found the answer though so thanks anyway.
_________________
http://putzpie.com

#151629 - tepples - Sat Mar 01, 2008 6:27 pm

putzpie wrote:
I wish I knew how to explain it better. what I mean by an object would be like, say some text

In turn, please define "some text". What attributes does a piece of text have? I ask you to define things in increasing amounts of detail because eventually, you'll end up defining it in enough detail that you can implement it.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#151631 - putzpie - Sat Mar 01, 2008 6:53 pm

Ok, I'm going to explain it to the best of my abilities, so here goes nothing.

What I have is some regular text that you display using printf() on the console. 3 of them are "more" and 3 of them are "less" (that's what they say.) I already have code made so that if you touch either more/less it'll do it's function, which is to increase the R,B, or G of the screen on top. I want to know, is there an easier way to do this than define "a box" around said text, where I check for input. Like instead of hard coding where the box is I want it to be more flexible and be able to touch it so that it returns a value like which string is being touched, but I'm supposing you can't do this with regular, static text, can you?
_________________
http://putzpie.com

#151637 - tepples - Sat Mar 01, 2008 8:07 pm

putzpie wrote:
What I have is some regular text that you display using printf() on the console.

So for each of the six strings, you have several attributes: left side of text, top of text, string length, (implicit constant) font size.

Quote:
Like instead of hard coding where the box is I want it to be more flexible and be able to touch it so that it returns a value like which string is being touched

The typical method is that you make the boxes, and then you have both the display code and the touch code use the same boxes. Start with an array of (left, top, right, bottom, what) structs. The code that draws the text on the screen reads the array to see what and where to draw. For example, it could printf escape codes based on left and top, and then draw text based on what. The hit-detection code reads the same array to translate touch positions into element indices. Then when you add an element to the array, it will be both displayed and touchable.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.