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.

DS development > Detecting when an sprite is chased inside a stylus draw

#134880 - Quien - Tue Jul 17, 2007 10:46 pm

Hello.

I am starting to program with PaLIB for Nintendo DS and after reading all the tutorials and making some simple tests, I have started programming my first serious game.

Everything goes OK but now I want to detect when the user draws on the touchscreen a circle which surrounds one -and only one- sprite. Is there any function or sample code for that or do I have to calculate it using only the coordinates I receive for each point drawed on the screen?

#134895 - tepples - Wed Jul 18, 2007 1:34 am

Yes, you have to do it with the stream of coordinates that touch gives you. Do you know how lasso tools in Paint, Paint.NET, GIMP, Photoshop, or other paint programs work?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#134951 - Quien - Wed Jul 18, 2007 9:24 pm

I know how they work from the outside...I mean, I use that programs and I know they draw a closed shape when you draw its outline with the mouse. But if you refer to how they are internally programmed, I have no idea. I suppose I cannot store every pixel painted by the user, and that I should join the last point with the first one...but I don't have very clear how to implement it.

#134953 - tepples - Wed Jul 18, 2007 9:32 pm

As the user draws, you build a list of points that the user passed the stylus over, which can also be considered a list of line segments from one point to the next. For each sprite, you use the odd-even algorithm to determine whether it is on the inside or outside of this border. If and only if there are an odd number of line segments to the left of each point, then the point is inside the region.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.