Пример #1
0
        public void FromPointsTest()
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.iOS, 8, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 10, throwIfOtherPlatform: false);

            var pts = new[] {
                new CGPoint(0, 0),
                new CGPoint(320, 568)
            };

            var result = SKShapeNode.FromPoints(pts);

            Assert.IsNotNull(result, "result should not be null");
        }
Пример #2
0
        public void FromPointsOffsetTest()
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.iOS, 8, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 10, throwIfOtherPlatform: false);

            var pts = new [] {
                new CGPoint(0, 0),
                new CGPoint(320, 568)
            };

            var result = SKShapeNode.FromPoints(pts, 1, 1);

            Assert.IsNotNull(result, "result should not be null");

            Assert.Throws <InvalidOperationException> (() => SKShapeNode.FromPoints(pts, 1, 2));
        }
Пример #3
0
        public void FromPointsTest()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(8, 0))
            {
                Assert.Ignore("requires iOS8+");
            }

            var pts = new[] {
                new PointF(0, 0),
                new PointF(320, 568)
            };

            var result = SKShapeNode.FromPoints(pts);

            Assert.IsNotNull(result, "result should not be null");
        }
Пример #4
0
        public void FromPointsOffsetTest()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(8, 0))
            {
                Assert.Ignore("requires iOS8+");
            }

            var pts = new [] {
                new PointF(0, 0),
                new PointF(320, 568)
            };

            var result = SKShapeNode.FromPoints(pts, 1, 1);

            Assert.IsNotNull(result, "result should not be null");

            Assert.Throws <InvalidOperationException> (() => SKShapeNode.FromPoints(pts, 1, 2));
        }
Пример #5
0
        public override void DidMoveToView(SKView view)
        {
            base.DidMoveToView(view);

            var follower = new AgentNode(this, DefaultAgentRadius, new CGPoint(Frame.GetMidX(), Frame.GetMidY()))
            {
                Color = SKColor.Cyan
            };

            var center = new Vector2((float)Frame.GetMidX(), (float)Frame.GetMidY());
            var points = new [] {
                new Vector2(center.X, center.Y + 50),
                new Vector2(center.X + 50, center.Y + 150),
                new Vector2(center.X + 100, center.Y + 150),
                new Vector2(center.X + 200, center.Y + 200),
                new Vector2(center.X + 350, center.Y + 150),
                new Vector2(center.X + 300, center.Y),
                new Vector2(center.X, center.Y - 200),
                new Vector2(center.X - 200, center.Y - 100),
                new Vector2(center.X - 200, center.Y),
                new Vector2(center.X - 100, center.Y + 50),
            };

            var path = GKPath.FromPoints(points, DefaultAgentRadius, true);

            follower.Agent.Behavior = GKBehavior.FromGoal(GKGoal.GetGoalToFollowPath(path, 1.5, true), 1);
            AgentSystem.AddComponent(follower.Agent);

            var cgPoints = new CGPoint[11];

            for (var i = 0; i < 10; i++)
            {
                cgPoints [i] = new CGPoint(points [i].X, points [i].Y);
            }

            cgPoints [10] = cgPoints [0];
            var pathShape = SKShapeNode.FromPoints(ref cgPoints [0], 11);

            pathShape.LineWidth   = 2;
            pathShape.StrokeColor = SKColor.Magenta;
            AddChild(pathShape);
        }
Пример #6
0
        public void InitAgent(SKScene scene, float radius, CGPoint position)
        {
            Position  = position;
            ZPosition = 10f;
            scene.AddChild(this);

            Agent = new GKAgent2D {
                Radius          = radius,
                Position        = new Vector2((float)position.X, (float)position.Y),
                Delegate        = this,
                MaxSpeed        = 100f,
                MaxAcceleration = 50f
            };

            var circleShape = SKShapeNode.FromCircle(radius);

            circleShape.LineWidth = 2.5f;
            circleShape.FillColor = SKColor.Gray;
            circleShape.ZPosition = 1f;
            AddChild(circleShape);

            const float triangleBackSideAngle = (float)((135f / 360f) * (2 * Math.PI));
            var         points = new [] {
                new CGPoint(radius, 0f),                                                                          // Tip
                new CGPoint(radius * Math.Cos(triangleBackSideAngle), radius * Math.Sin(triangleBackSideAngle)),  // Back bottom
                new CGPoint(radius * Math.Cos(triangleBackSideAngle), -radius * Math.Sin(triangleBackSideAngle)), // Back top
                new CGPoint(radius, 0f)                                                                           // Back top
            };

            TriangleShape           = SKShapeNode.FromPoints(ref points [0], (nuint)points.Length);
            TriangleShape.LineWidth = 2.5f;
            TriangleShape.ZPosition = 1f;
            AddChild(TriangleShape);

            Particles            = SKNode.FromFile <SKEmitterNode> ("Trail.sks");
            DefaultParticleRate  = (float)Particles.ParticleBirthRate;
            Particles.Position   = new CGPoint(-radius + 5, 0);
            Particles.TargetNode = scene;
            Particles.ZPosition  = 0f;
            AddChild(Particles);
        }