2016年5月17日 星期二
0517 cocos2d touch 觸碰偵測
1.說明:
改用 convertToNodeSpace 此函數偵測碰觸範圍
2. 每次皆需要根據 getContentSize 重新建立範圍
不可以用 getBox....
bool UIMap::onTouchBegan(Touch* touch, Event* event)
{
auto target = static_cast<Layer*>(event->getCurrentTarget());
if(target==nullptr)
{
return true;
}
log("%s",__PRETTY_FUNCTION__);
// Vec2 touchLocation = touch->getLocation();
// Vec2 nodePosition = target->convertToNodeSpace( touchLocation );
if(!isVisible())
return false;
// int iSel=checkTouchItem(nodePosition);
int iSel=checkItemByTouch(touch);
}
//改用其他函數 避免因為座標系統不一致會有問題
int UIPAGE::checkItemByTouch(Touch* touch)
{
auto sprites=m_NodeVectors.at(PG_REMOTEMAIN);
auto bTouch =false;
for(auto pSprite:*sprites)
{
auto iIdx=pSprite->getTag();
if(pSprite->isVisible() && checkTouchNode(iIdx))
{
Vec2 touchPost=pSprite->convertTouchToNodeSpace(touch);
Size boxSize=pSprite->getContentSize();
Rect boxRect=Rect(0,0,boxSize.width,boxSize.height);
bTouch = boxRect.containsPoint(touchPost);
if(bTouch)
{
return iIdx;
break;
}
}
}
return -1;
}
訂閱:
張貼留言 (Atom)
cocos2dx-lua 建立滑鼠監聽
重要關鍵字 EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority if IsPc() then --建立滑鼠監聽 local listener = cc.EventListenerMouse...
-
本身常用範例 auto pFrame= SpriteFrameCache::getInstance()->getSpriteFrameByName(test); m_IconBox->setSpriteFrame(pFrame); http://cocos2...
-
http://blog.csdn.net/teng_ontheway/article/details/26078869 遊戲中經常會用到一些變換: 遊戲中武器和角色在一個layer上,為了效率,會考慮將bullet, effect和 PhysicsParticle分別放...
-
如何將IPA 透過ITUNES 安裝到 手機中 1.插上iPhone,開啟 iTunes,點選選單 檢視->媒體種類->APP 。iTunes 會切換至APP頁面 2.開啟檔案總管 將 .ipa 檔案 利用滑鼠拉進 iTunes。然後...
沒有留言:
張貼留言