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...
-
https://changeyu.wordpress.com/2015/03/25/%E4%BD%A0%E7%9A%84macbook-air%E7%B8%BD%E6%98%AF%E7%A9%BA%E9%96%93%E4%B8%8D%E5%A4%A0%E5%97%8E%EF%BC...
-
VS2013 編譯cocos2d 3.12 出現 Error C1083: can’t open “extensions/ExtensionMacros.h” 在設定中加上 $(EngineRoot) 即可解決 property->configure propert...
-
1. 安裝 Node 下載網頁 https://nodejs.org/en/download/ 下載檔案 node-v6.7.0-x64.msi 執行安裝 安裝完畢 可以控制台cmd 下執行 node -v 如有版本就是安裝完畢了 2. 安装compon...
沒有留言:
張貼留言