Esempio n. 1
0
        protected internal override void Step(float dt)
        {
            CCFollow followAction    = FollowAction;
            CCPoint  followedNodePos = followAction.FollowedNode.Position;

            if (followAction.UsingBoundary)
            {
                // whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased
                if (followAction.BoundaryFullyCovered)
                {
                    return;
                }

                CCPoint tempPos = cachedHalfScreenSize - followedNodePos;

                Target.Position = new CCPoint(
                    MathHelper.Clamp(tempPos.X, cachedBoundary.LeftBoundary, cachedBoundary.RightBoundary),
                    MathHelper.Clamp(tempPos.Y, cachedBoundary.BottomBoundary, cachedBoundary.TopBoundary)
                    );
            }
            else
            {
                Target.Position = cachedHalfScreenSize - followedNodePos;
            }
        }
Esempio n. 2
0
        public CCFollowState(CCFollow action, CCNode target) : base(action, target)
        {
            // Cache these structs so we don't have to get them at each running step
            CCFollow followAction = FollowAction;

            cachedBoundary       = followAction.Boundary;
            cachedHalfScreenSize = followAction.HalfScreenSize;
        }
Esempio n. 3
0
 public CCFollowState (CCFollow action, CCNode target) : base (action, target)
 {
     // Cache these structs so we don't have to get them at each running step
     CCFollow followAction = FollowAction;
     cachedBoundary = followAction.Boundary;
     cachedHalfScreenSize = followAction.HalfScreenSize;
 }
        public override void OnEnter()
        {
            base.OnEnter();

            var visibleBounds = VisibleBoundsWorldspace;
            var origin = VisibleBoundsWorldspace.Origin;
            var size = VisibleBoundsWorldspace.Size;

            var sprite1 = new CCSprite("Images/CyanSquare.png");
            sprite1.Position = origin + size.Center + new CCPoint(-80, 80);
            AddChild(sprite1, 10);

            var follow = new CCFollow(sprite1, new CCRect(0, 0, 3000, 600));
            RunAction(follow);

            sprite1.PositionX = size.Width + 100;
            sprite1.PositionY = size.Height / 2;

            // Make sprite1 touchable
            var listener1 = new CCEventListenerTouchOneByOne();
            listener1.IsSwallowTouches = true;

            listener1.OnTouchBegan = (touch, touchEvent) =>
            {
                var layerOffset = Layer.PositionWorldspace;
                var target = (CCSprite)touchEvent.CurrentTarget;
                var locationInNode = touch.Location;

                CCRect rect = target.BoundingBoxTransformedToWorld;
                rect.Origin += layerOffset;

                if (rect.ContainsPoint(locationInNode))
                {
                    CCLog.Log("sprite began... x = {0}, y = {1}", locationInNode.X, locationInNode.Y);
                    target.Opacity = 180;
                    return true;
                }
                return false;
            };

            listener1.OnTouchMoved = (touch, touchEvent) =>
            {
                var target = (CCSprite)touchEvent.CurrentTarget;
                CCPoint pt = touch.PreviousLocation + touch.Delta;
                target.Position = target.WorldToParentspace(pt);
            };

            listener1.OnTouchEnded = (touch, touchEvent) =>
            {
                var target = (CCSprite)touchEvent.CurrentTarget;
                CCLog.Log("sprite onTouchesEnded..");
                target.Opacity = 255;
            };


            sprite1.AddEventListener(listener1);

        }