示例#1
0
        public override void DidMoveToView(SKView view)
        {
            cameraNode    = new SKCameraNode();
            Camera        = cameraNode;
            Camera.XScale = 0.5f;
            Camera.YScale = 0.5f;
            AddChild(cameraNode);

            mapNode          = new MapNode(CurrentMap);
            mapNode.Position = new CGPoint(mapNode.Position.X, mapNode.Position.Y + 100);
            AddChild(mapNode);

            mapNode.MapClicked += HandleTouchOnMap;
            mapNode.AddCharacter(Player);

            var comp = (CharacterSpriteComponent)Player.GetComponent(typeof(CharacterSpriteComponent));

            comp.Direction = Direction.North;
            comp.Walking   = false;

            SetupItemPositions();
            SetupCharacterPositions();

            SetCameraConstraints(cameraNode, comp.Sprite);
        }
示例#2
0
        void SetCameraConstraints(SKCameraNode camera, SKSpriteNode sprite)
        {
            // Constrain the camera to the player
            var          zeroRange        = new SKRange(0, 0);
            SKConstraint playerConstraint = SKConstraint.CreateDistance(zeroRange, sprite);

            var scaledSize  = new CGSize(Size.Width * camera.XScale, Size.Height * camera.YScale);
            var contentRect = mapNode.CalculateAccumulatedFrame();

            contentRect = new CGRect(contentRect.X, contentRect.Y, contentRect.Width, contentRect.Height + 300);

            nfloat xInset = (nfloat)Math.Min((scaledSize.Width / 2.0) + 10, contentRect.Width / 2.0);
            nfloat yInset = (nfloat)Math.Min((scaledSize.Height / 2.0) + 10, contentRect.Height / 2.0);

            var insetRect = contentRect.Inset(xInset, yInset);

            var xRange = new SKRange(insetRect.GetMinX(), insetRect.GetMaxX());
            var yRange = new SKRange(insetRect.GetMinY(), insetRect.GetMaxY());

            var levelEdgeConstraint = SKConstraint.CreateRestriction(xRange, yRange);

            levelEdgeConstraint.ReferenceNode = this;

            camera.Constraints = new[] { playerConstraint, levelEdgeConstraint };
        }
示例#3
0
        public override void DidMoveToView(SKView view)
        {
            _windowWidth  = view.Window.Frame.Width;
            _windowHeight = view.Window.Frame.Height;

            // Initialize camera
            Camera = new SKCameraNode()
            {
                Position = new CGPoint(_windowWidth / 2, _windowHeight / 2)
            };

            RenderScene();
        }