# how to accurately select a sprite on a scene with a click?

I have a scene with some sprite on it (added), the gamer has to select one of them and take the next action.

# What is the simplest way to select one of the sprites accurately?

I am looking for a method that recieves a click coordinate and returns one of the sprites on the scene.

Since the sprites cant be well fitted in a bounding box I dont like to use a minimum bounding box approximation.

I was thinking of loading the sprites into a matrix and creating a scene matrix that each member belongs to a specified sprite, but it costs a lot( each pixel must be transformed using an affine transformation and it must be recalculated each time one of the sprites move)

Can someone show me a better way with a lower cost?

P.S I am using Swift and Apple's SpriteKit There is a code for minimum bounding box but I am looking for an accurate method.

Inaccurate method if some interested is something like this :

     for touch in touches
{
var location : CGPoint = (touch as! UITouch).locationInNode(self)
for asprite in self.viewIso.children
{
if (asprite.containsPoint(location))
{
println("Selected : \(asprite.name as String)")
return
}
}
}


Thanks Iman

• It's great that you found a solution to your problem, but in the future if you're looking for a platform/language-specific solution it will be helpful for the rest of us if you indicate the platform/language in your question and/or tags. Also, you should accept your answer since you found your own solution. – Sandalfoot Jul 23 '15 at 18:42
• Actually, I didn't find my own answer, I was wrong so I deleted the answer, and thank you for suggestion to indicate the language and platform, I did, But I am looking for an algorithm. and about accepting my own answer, I should say that It will be possible after at least 24 hours. Why minus one???!?! – Iman Jul 23 '15 at 19:08
• The -1 was for you saying "this is the answer" and then posting code, when there was no way anyone would have known that you wanted a solution in that specific language. Your rewrite is a lot clearer so I'll reverse it. – Sandalfoot Jul 23 '15 at 19:15
• Thanks, beside the plus and minus, How do you do this? I want your answer, I am creating an isometric map kind of game and I need a good click and pick algorithm. – Iman Jul 23 '15 at 19:22
• Mick Waites gave you the correct answer, so I up voted him. – Sandalfoot Jul 23 '15 at 19:23