I have a scrollview at one side of the screen filled with CCSprites and I want to be able to drag one of them into the main area of the screen. I just need to find which Sprite the user started dragging on.
I have tried to move the Touch location into each Sprites coordinate space but the numbers are all over the place.
position is the Touch->getStartLocationInView()
ScrollViewItems is a Vector<Sprite*>
string HelloWorld::SpriteNameForPosition(cocos2d::Vec2* position)
{
for(Vector<Sprite*>::iterator iter = scrollViewItems.begin() ;iter != scrollViewItems.end();iter++)
{
Sprite* sprite = *iter;
Vec2 spriteTouchPos = sprite->convertToNodeSpace(*position);
Rect bounds = Rect(0, 0, sprite->getBoundingBox().size.width, sprite->getBoundingBox().size.height);
if(bounds.containsPoint(spriteTouchPos))
{
return names[sprite->getTag()];
}
}
return "";
}