Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a set of sprites, each one implementing InputProcessor, and registered to an InputMultiplexer, when a sprite is touched, everyone fires the touchDown event.

Ok, so I can get the touch coordinates, unproject, and compare with the sprite bounds to know if it was touched, but it wasn't what I had in mind when I implemented InputProcessor into my sprites, I thought only the touched one would fire.

Don't even know if it is a problem, I'm planning to have about 80 sprites reacting to touch. Is this the best solution?

Is there a way to fire an event only for the touched sprite?

I'm not using scene2d or actors.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Ok, so I can get the touch coordinates, unproject, and compare with the sprite bounds to know if it was touched

This is how I would proceed, especially for only 80 sprites. How is the InputProcessor to know to fire only when certain geometry is touched? There's no concept of geometry for an InputProcessor. I recently implemented a similar model with 10,000 sprites - each with their own InputProcessor (a GestureDetector, actually). While this worked just fine on PC, Android had significant (perhaps 1 second) lag between touch and full render.

The other way this is commonly done is to have just one input processor, and 'find' the sprite under the touched area in that context (perhaps by drawing a ray from the camera's plane at the x,y of the touch event, and using an Intersector to find the intersecting object).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.