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://cocosgamestory.wordpress.com/2015/08/12/%E6%9B%B4%E6%8F%9B%E6%96%B0%E7%9A%84appicon/ 使用心得: 透過網站 取得各種SIZE的ICON,在手動更換目錄下的ICON即可 (coco...
-
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...
-
https://medium.com/@yujiewang/rails-visual-studio-code-%E4%BF%AE%E6%94%B9-tab%E8%A8%AD%E5%AE%9A-74b0fc748f28 寫Ruby的時候依據慣例會習慣使用 2 個空白來設定縮排 但...
沒有留言:
張貼留言