コード例 #1
0
ファイル: PlayerSprite.cpp プロジェクト: ungod/PieceProj
void PlayerSprite::ccTouchMoved( CCTouch *pTouch, CCEvent *pEvent )
{
	if (!m_bIsTouch) return;

	CCNode* parent = getParent();
	if (parent)
	{
		setPosition(parent->convertTouchToNodeSpace(pTouch));
	}
}
コード例 #2
0
ファイル: LayerMenu.cpp プロジェクト: MasterBC/Mario
void LayerMenu::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
	if (isClick(pTouch))
	{
		CCNode* node = _view->getContainer();
		CCPoint ptInNode = node->convertTouchToNodeSpace(pTouch);
		for (int i = 0; i < 8; ++i)
		{
			CCSprite* sprite = (CCSprite*)node->getChildByTag(1000 + i);
			if (sprite->boundingBox().containsPoint(ptInNode))
			{
				//进入游戏场景
				CCDirector::sharedDirector()->replaceScene(Common::scene(LayerGame::create(i)));
				break;
			}
		}
	}
}
コード例 #3
0
ファイル: ScutCxListItem.cpp プロジェクト: acekiller/Scut
	void ScutCxListItem::MyTouchDispatcher(CCNode* pParent, int nToutchEvent, CCTouch* touch, CCEvent* event)
	{

			CCNode* parent = pParent;
			while(parent)
			{	
				//对嵌套列表TOUCH END 做事件传递
				//if (parent->getClassType() == ScutLIST_classID && nToutchEvent == TOUCHEND)
				//	break;

				if(findInDeque(pParent))
				{
					 if(nToutchEvent == TOUCHEND)
						break;
				}

				CCPoint pos_parent =  parent->getPosition();
				CCPoint pos_in_parent  = parent->convertTouchToNodeSpace(touch);										
				CCSize  size_parent = parent->getContentSize();


				////对横屏例表作特殊处理
				if(pos_parent.x < 0)
					pos_in_parent.x = pos_in_parent.x + pos_parent.x;


				CCRect r;
				r.origin	= CCPointZero;
				r.size		= size_parent;

				if (!r.containsPoint(pos_in_parent))
				{

					if(pos_parent.y > 0)
					{
						//对竖屏例表作特殊处理
						pos_in_parent.y = pos_in_parent.y + pos_parent.y;
						if (!r.containsPoint(pos_in_parent))
						{
							return;
						}
					}
					else
					{
						return;
					}
				}				
				parent = parent->getParent();
			}



		switch(nToutchEvent)
		{			
			case TOUCHBEGIN:
				{
					if(dynamic_cast<CCLayer*>(pParent) != NULL)
				{
					bool bCatch = ((CCLayer*)pParent)->ccTouchBegan(touch,event);
					if(bCatch && findInTouchEventLayerDeque(pParent) )
					{
						m_pVectorTouchBegan.push_back((CCLayer*)pParent);						
						m_bCatchEndNode = true;	
						g_bCatchLayer = true;
					}
				}

				if (pParent && pParent->getChildren())
				{
					CCNode* pItem = NULL; 
					for (int i = 0, l = pParent->getChildren()->count(); i < l; ++i)
					{
						pItem = (CCNode *)pParent->getChildren()->objectAtIndex(i);		 
						if(pItem)
						{
							MyTouchDispatcher(pItem, nToutchEvent,touch,event);
						}						 
					}	 
				}
			}
			break;

		case TOUCHEND:
			{

				if(dynamic_cast<CCLayer*>(pParent) != NULL)
					((CCLayer*)pParent)->ccTouchEnded(touch,event);
				if (pParent && pParent->getChildren())
				{
					CCNode* pItem = NULL; 
					for (int i = 0, l = pParent->getChildren()->count(); i < l; ++i)
					{
						pItem = (CCNode *)pParent->getChildren()->objectAtIndex(i);
						if(pItem)
						{
							MyTouchDispatcher(pItem, nToutchEvent,touch,event);
						}
					}	 
				}

			}
			break;

		case TOUCHMOVING:
			{

				if(dynamic_cast<CCLayer*>(pParent) != NULL)			
					((CCLayer*)pParent)->ccTouchMoved(touch,event);
				if (pParent && pParent->getChildren())
				{
					CCNode* pItem = NULL; 
					for (int i = 0, l = pParent->getChildren()->count(); i < l; ++i)
					{
						pItem = (CCNode *)pParent->getChildren()->objectAtIndex(i);
						if(pItem)
						{
							MyTouchDispatcher(pItem, nToutchEvent,touch,event);
						}
					}	 
				}

			}
			break;
			
		case TOUCHCANCELLED:
			{				 
				if(dynamic_cast<CCLayer*>(pParent) != NULL)
					((CCLayer*)pParent)->ccTouchCancelled(touch,event);
				if (pParent && pParent->getChildren())
				{
					CCNode* pItem = NULL; 
					for (int i = 0, l = pParent->getChildren()->count(); i < l; ++i)
					{
						pItem = (CCNode *)pParent->getChildren()->objectAtIndex(i);
						if(pItem)
						{
							MyTouchDispatcher(pItem, nToutchEvent,touch,event);
						}
					}	 
				}
			}
			break;

		default:
			break;

		}
	}