touch listener CCSprite

I need detect touch on CCSprite.
Thank you!

Hi,

More info would have been welcomed (what are you trying to achieve exactly?) but mostly you’ll have to subclass a CCLayer and enable touch. Then when a touch is intercepted (touchBegan) just check that the touch is within the sprite’s bounding box.

Hope it helps.

You’re invited to investigate how CCMenu detects touch on its items. From CCMenu.cpp:

CCMenuItem* CCMenu::itemForTouch(CCTouch *touch)
{
    CCPoint touchLocation = touch->getLocation();

    if (m_pChildren && m_pChildren->count() > 0)
    {
        CCObject* pObject = NULL;
        CCARRAY_FOREACH(m_pChildren, pObject)
        {
            CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject);
            if (pChild && pChild->isVisible() && pChild->isEnabled())
            {
                CCPoint local = pChild->convertToNodeSpace(touchLocation);
                CCRect r = pChild->rect();
                r.origin = CCPointZero;

                if (r.containsPoint(local))
                {
                    return pChild;
                }
            }
        }
    }

    return NULL;
}

How about component system: http://www.cocos2d-x.org/forums/18/topics/44141 ? Maybe give it a try.