We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Sprites for Processing Library
Page Index Toggle Pages: 1
Sprites for Processing Library (Read 985 times)
Sprites for Processing Library
Feb 5th, 2010, 3:58am
 
Keaton_R said
Quote:
Quark, I was wondering if you could add in some methods to check whether or not a sprite collides with a point (an x and y coordinate). I need to be able to check whether I am touching a sprite on a touch-screen device, so the mouse events don't help. I need to be able to provide the x and y coordinate of where I'm touching the screen to the sprite class so that the sprite can tell me whether or not I'm touching it.


I haven't programmed for touch screen devices but when you touch the screen does that not create a 'button click' event?

If it does then if you have a sprite called s then
Code:
s.respondToMouse(true); 


means that the sprite will respond to mouse events by calling this method (code taken from S4P_Showcase example)

Code:
/*
* S4P Eventhandler called mouse is PRESSED, RELEASED
* or CLICKED over the sprite.
*
* @param sprite
*/
void handleSpriteEvents(Sprite sprite) {
 println("Mouse clicked");
 if(sprite.eventType == Sprite.CLICKED){
   selSprite = sprite;
   updateGUI();
 }
}


Note other events include PRESSED, RELEASED and DRAGGED

You can also make the sprite draggable with
Code:
s.setDraggable(true); 



Does this help?

Smiley
Re: Sprites for Processing Library
Reply #1 - Feb 8th, 2010, 1:23pm
 
Quark wrote on Feb 5th, 2010, 3:58am:
I haven't programmed for touch screen devices but when you touch the screen does that not create a 'button click' event




In my case, no it does not create a "button click" event. In processing, I can get a List of  "new touches", "moved touches", and "released touches" every frame. Each touch has an x and y coordinate. I need to  check whether or not these "touches" collide with a sprite.

My first idea was to create a sprite at the location of each touch and see if it collides with my other sprites. I ran into some issues though, like creating 60 sprites  per second and crashing processing if I didn't remove my finger quickly enough.

I'm may try to make a class that associates one of my Touch objects with one of your Sprite objects that knows to make a new TouchSprite whenever I touch the screen. Knows to move it when I move my finger, and knows to delete it when I remove my finger. I'll need to get a better understanding of your library first though.

I think that simply being able to check if a Sprite contains a Point object would suit me for now though. Seems like it would be useful in a lot of situations.
Re: Sprites for Processing Library
Reply #2 - Feb 9th, 2010, 12:06pm
 
Yes I agree it would be useful and it now available in Sprites for Processing V1.0.3

If you have a sprite object called s then the following
Code:
s.isOver(x,y) 


will return true if position x,y is over a non-transparent pixel in the sprite else it returns false.
Cheesy
Page Index Toggle Pages: 1