My own class inherit from CCLayer, but somehow it rigster standardTouchDelegate failed at first.
CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0);
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
{
CCTouchHandler *pHandler = CCStandardTouchHandler::handlerWithDelegate(pDelegate, nPriority);
if (! m_bLocked)
{
forceAddHandler(pHandler, m_pStandardHandlers);
}
else
{
m_pHandlersToAdd->addObject(pHandler);
m_bToAdd = true;
}
}
the m_bLocked is true, so it add to m_pHandlersToAdd.
then
if (m_bToAdd)
{
m_bToAdd = false;
CCMutableArray::CCMutableArrayIterator iter;
CCTouchHandler *pHandler;
for (iter = m_pHandlersToAdd->begin(); iter != m_pHandlersToAdd->end(); ++iter)
{
pHandler = *iter;
if (! pHandler)
{
break;
}
if (pHandler->getDelegate()->getTouchDelegateType() & ccTouchDelegateTargetedBit)
{
forceAddHandler(pHandler, m_pTargetedHandlers);
}
else
{
forceAddHandler(pHandler, m_pStandardHandlers);
}
}
m_pHandlersToAdd->removeAllObjects();
}
but,
CCLayer::CCLayer()
:m_bIsTouchEnabled(false)
,m_bIsAccelerometerEnabled(false)
,m_bIsKeypadEnabled(false)
,m_bIsMouseEnabled(false)
,m_bIsKeyboardEnabled(false)
{
m_eTouchDelegateType = ccTouchDeletateAllBit;
m_tAnchorPoint = ccp(0.5f, 0.5f);
m_bIsRelativeAnchorPoint = false;
}
So, you can see following judgement is always true for CCLayer, in another word standardTouch changes to TargetTouch.
if (pHandler->getDelegate()->getTouchDelegateType() & ccTouchDelegateTargetedBit)
{
forceAddHandler(pHandler, m_pTargetedHandlers);
}
so, I got the error :
Assertion failed: (false), function ccTouchBegan, cocos2dx/platform/CCLayer_mobile.cpp, line 298.