protected CCMenuItem itemForTouch(CCTouch touch) { //XNA point CCPoint touchLocation = touch.locationInView(touch.view()); //cocos2d point touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation); if (m_pChildren != null && m_pChildren.Count > 0) { foreach (var pChild in m_pChildren) { if (pChild != null && pChild.visible && ((CCMenuItem)pChild).Enabled) { CCPoint local = pChild.convertToNodeSpace(touchLocation); CCRect r = ((CCMenuItem)pChild).rect(); r.origin = CCPoint.Zero; if (CCRect.CCRectContainsPoint(r, local)) { return((CCMenuItem)pChild); } } } } return(null); }
public override void ccTouchEnded(CCTouch pTouch, CCEvent pEvent) { if (m_pTrackNode != null) { return; } CCPoint endPos = pTouch.locationInView(pTouch.view()); endPos = CCDirector.sharedDirector().convertToGL(endPos); float delta = 5.0f; if (Math.Abs(endPos.x - m_beginPos.x) > delta || Math.Abs(endPos.y - m_beginPos.y) > delta) { // not click m_beginPos.x = m_beginPos.y = -1; return; } // decide the trackNode is clicked. CCRect rect; CCPoint point = convertTouchToNodeSpaceAR(pTouch); Debug.WriteLine("KeyboardNotificationLayer:clickedAt(%f,%f)", point.x, point.y); rect = TextInputTestScene.getRect(m_pTrackNode); Debug.WriteLine("KeyboardNotificationLayer:TrackNode at(origin:%f,%f, size:%f,%f)", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); this.onClickTrackNode(CCRect.CCRectContainsPoint(rect, point)); Debug.WriteLine("----------------------------------"); }
protected CCMenuItem itemForTouch(CCTouch touch) { CCMenuItem cCMenuItem; CCPoint gL = touch.locationInView(touch.view()); gL = CCDirector.sharedDirector().convertToGL(gL); if (this.m_pChildren != null && this.m_pChildren.Count > 0) { List <CCNode> .Enumerator enumerator = this.m_pChildren.GetEnumerator(); try { while (enumerator.MoveNext()) { CCNode current = enumerator.Current; if (current == null || !current.visible || !((CCMenuItem)current).Enabled) { continue; } CCPoint nodeSpace = current.convertToNodeSpace(gL); CCRect zero = ((CCMenuItem)current).rect(); zero.origin = CCPoint.Zero; if (!CCRect.CCRectContainsPoint(zero, nodeSpace)) { continue; } cCMenuItem = (CCMenuItem)current; return(cCMenuItem); } return(null); } finally { ((IDisposable)enumerator).Dispose(); } return(cCMenuItem); } return(null); }