Ejemplo n.º 1
0
        public override void ccTouchMoved(CCTouch touch, CCEvent parmevent)
        {
            CCPoint touchLocation = touch.locationInView(touch.view());
            CCPoint prevLocation = touch.previousLocationInView(touch.view());

            touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation);
            prevLocation = CCDirector.sharedDirector().convertToGL(prevLocation);

            CCPoint diff = new CCPoint(touchLocation.x - prevLocation.x, touchLocation.y - prevLocation.y);

            CCNode node = getChildByTag(1);
            CCPoint currentPos = node.position;
            node.position = new CCPoint(currentPos.x + diff.x, currentPos.y + diff.y);
        }
Ejemplo n.º 2
0
        /// <summary>converts a CCTouch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).</summary>
        public CCPoint ConvertTouchToNodeSpaceAR(CCTouch touch)
        {
            CCPoint point = touch.locationInView(touch.view());

            point = Director.SharedDirector.ConvertToGL(point);
            return(this.ConvertToNodeSpaceAR(point));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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("----------------------------------");
        }
Ejemplo n.º 5
0
 // CCLayer
 public override bool ccTouchBegan(CCTouch pTouch, CCEvent pEvent)
 {
     Debug.WriteLine("++++++++++++++++++++++++++++++++++++++++++++");
     m_beginPos = pTouch.locationInView(pTouch.view());
     m_beginPos = CCDirector.sharedDirector().convertToGL(m_beginPos);
     return(true);
 }
Ejemplo n.º 6
0
        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("----------------------------------");
        }
Ejemplo n.º 7
0
 // CCLayer
 public override bool ccTouchBegan(CCTouch pTouch, CCEvent pEvent)
 {
     Debug.WriteLine("++++++++++++++++++++++++++++++++++++++++++++");
     m_beginPos = pTouch.locationInView(pTouch.view());
     m_beginPos = CCDirector.sharedDirector().convertToGL(m_beginPos);
     return true;
 }
Ejemplo n.º 8
0
        public CCPoint convertTouchToNodeSpaceAR(CCTouch touch)
        {
            CCPoint obPoint = touch.locationInView(touch.view());

            obPoint = CCDirector.sharedDirector().convertToGL(obPoint);
            return(this.convertToNodeSpaceAR(obPoint));
        }
Ejemplo n.º 9
0
 public void updateSize(CCTouch touch)
 {
     CCPoint touchLocation = touch.locationInView(touch.view());
     touchLocation = CCDirector.sharedDirector().convertToGL(touchLocation);
     CCSize s = CCDirector.sharedDirector().getWinSize();
     CCSize newSize = new CCSize(Math.Abs(touchLocation.x - s.width / 2) * 2, Math.Abs(touchLocation.y - s.height / 2) * 2);
     CCLayerColor l = (CCLayerColor)getChildByTag(kTagLayer);
     l.contentSize = newSize;
 }
        public virtual void ccTouchEnded(CCTouch touch, CCEvent eventer)
        {
            CCPoint touchPoint = touch.locationInView(touch.view());
            CCPoint convertedLocation = CCDirector.sharedDirector().convertToGL(touchPoint);

            //执行运动
            CCActionInterval move = CCMoveTo.actionWithDuration(3, convertedLocation);
            CCActionInterval move_ease_inout = CCEaseInOut.actionWithAction(move);//ease缓冲
            base.runAction(move_ease_inout);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// converts a CCTouch (world coordinates) into a local coordiante. This method is AR (Anchor Relative).
 /// @since v0.7.1
 /// </summary>
 public CCPoint convertTouchToNodeSpaceAR(CCTouch touch)
 {
     CCPoint point = touch.locationInView(touch.view());
     point = CCDirector.sharedDirector().convertToGL(point);
     return this.convertToNodeSpaceAR(point);
 }
Ejemplo n.º 14
0
        public virtual void ccTouchMoved(CCTouch touch, CCEvent eventer)
        {
            // If it weren't for the TouchDispatcher, you would need to keep a reference
            // to the touch from touchBegan and check that the current touch is the same
            // as that one.
            // Actually, it would be even more complicated since in the Cocos dispatcher
            // you get CCSets instead of 1 UITouch, so you'd need to loop through the set
            // in each touchXXX method.

            Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!");

            CCPoint touchPoint = touch.locationInView(touch.view());
            touchPoint = CCDirector.sharedDirector().convertToGL(touchPoint);

            base.position = new CCPoint(touchPoint.x, base.position.y);
        }
Ejemplo n.º 15
0
        public override void ccTouchEnded(CCTouch touch, CCEvent eve)
        {
            CCPoint location = touch.locationInView( touch.view() );
            CCPoint convertedLocation = CCDirector.sharedDirector().convertToGL(location);

            CCPoint pos = new CCPoint(0,0);
            if (m_background != null)
            {
                pos = m_background.convertToWorldSpace(new CCPoint(0,0));
            }
            m_emitter.position = CCPointExtension.ccpSub(convertedLocation, pos);
        }
Ejemplo n.º 16
0
 /// <summary>convenience methods which take a CCTouch instead of CCPoint </summary>
 public CCPoint ConvertTouchToNodeSpace(CCTouch touch)
 {
     CCPoint point = touch.locationInView(touch.view());
     point = Director.SharedDirector.ConvertToGL(point);
     return this.ConvertToNodeSpace(point);
 }