当前位置: 首页>>代码示例>>C#>>正文


C# CCRect.ContainsPoint方法代码示例

本文整理汇总了C#中cocos2d.CCRect.ContainsPoint方法的典型用法代码示例。如果您正苦于以下问题:C# CCRect.ContainsPoint方法的具体用法?C# CCRect.ContainsPoint怎么用?C# CCRect.ContainsPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cocos2d.CCRect的用法示例。


在下文中一共展示了CCRect.ContainsPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TouchMoved

        public override void TouchMoved(CCTouch touch, CCEvent pEvent)
        {
            if (!Visible)
            {
                return;
            }

            if (m_pTouches.Contains(touch))
            {
                if (m_pTouches.Count == 1 && m_bDragging)
                {
                    // scrolling

                    m_bTouchMoved = true;
                    CCPoint frameOriginal = Parent.ConvertToWorldSpace(Position);
                    var frame = new CCRect(frameOriginal.X, frameOriginal.Y, m_tViewSize.Width, m_tViewSize.Height);
                    CCPoint newPoint = ConvertTouchToNodeSpace(m_pTouches[0]);
                    CCPoint moveDistance = CCPointExtension.Subtract(newPoint, m_tTouchPoint);
                    m_tTouchPoint = newPoint;

                    if (frame.ContainsPoint(ConvertToWorldSpace(newPoint)))
                    {
                        switch (m_eDirection)
                        {
                            case CCScrollViewDirection.Vertical:
                                moveDistance = new CCPoint(0.0f, moveDistance.Y);
                                break;
                            case CCScrollViewDirection.Horizontal:
                                moveDistance = new CCPoint(moveDistance.X, 0.0f);
                                break;
                        }

                        m_pContainer.Position = CCPointExtension.Add(m_pContainer.Position, moveDistance);

                        CCPoint maxInset = m_fMaxInset;
                        CCPoint minInset = m_fMinInset;

                        //check to see if offset lies within the inset bounds
                        float newX = Math.Min(m_pContainer.Position.X, maxInset.X);
                        newX = Math.Max(newX, minInset.X);
                        float newY = Math.Min(m_pContainer.Position.Y, maxInset.Y);
                        newY = Math.Max(newY, minInset.Y);

                        m_tScrollDistance = CCPointExtension.Subtract(moveDistance,
                                                                    new CCPoint(newX - m_pContainer.Position.X, newY - m_pContainer.Position.Y));
                        SetContentOffset(new CCPoint(newX, newY), false);
                    }
                }
                else if (m_pTouches.Count == 2 && !m_bDragging)
                {
                    float len = CCPointExtension.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]),
                                                             m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1]));
                    ZoomScale = ZoomScale * len / m_fTouchLength;
                }
            }
        }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:56,代码来源:CCScrollView.cs

示例2: TouchBegan

        /** override functions */
        // optional
        public override bool TouchBegan(CCTouch pTouch, CCEvent pEvent)
        {
            if (!Visible)
            {
                return false;
            }

            CCPoint frameOriginal = Parent.ConvertToWorldSpace(Position);
            var frame = new CCRect(frameOriginal.X, frameOriginal.Y, m_tViewSize.Width, m_tViewSize.Height);

            //dispatcher does not know about clipping. reject touches outside visible bounds.
            if (m_pTouches.Count > 2 ||
                m_bTouchMoved ||
                !frame.ContainsPoint(m_pContainer.ConvertToWorldSpace(m_pContainer.ConvertTouchToNodeSpace(pTouch))))
            {
                return false;
            }

            if (!m_pTouches.Contains(pTouch))
            {
                m_pTouches.Add(pTouch);
            }

            if (m_pTouches.Count == 1)
            {
                // scrolling
                m_tTouchPoint = ConvertTouchToNodeSpace(pTouch);
                m_bTouchMoved = false;
                m_bDragging = true; //dragging started
                m_tScrollDistance = new CCPoint(0.0f, 0.0f);
                m_fTouchLength = 0.0f;
            }
            else if (m_pTouches.Count == 2)
            {
                m_tTouchPoint = CCPointExtension.Midpoint(ConvertTouchToNodeSpace(m_pTouches[0]),
                                                             ConvertTouchToNodeSpace(m_pTouches[1]));
                m_fTouchLength = CCPointExtension.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]),
                                                              m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1]));
                m_bDragging = false;
            }
            return true;
        }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:44,代码来源:CCScrollView.cs


注:本文中的cocos2d.CCRect.ContainsPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。