Example #1
0
        // Generate the sparks particles
        private void GenerateSparks()
        {
            // Inital speed
            var speed = 0;

            // Generate 3 nodes per 6 rows
            for (int i = 1; i <= 3; i++)
            {
                for (int y = 1; y <= 6; y++)
                {
                    // Calculate location of each Spark (5 Sparks per row, for 10 rows)
                    var location = new CGPoint();
                    location.X = (((View.Frame.Width / 6) * (2 * i)) - (View.Frame.Width / 6));
                    location.Y = (((View.Frame.Height / 12) * (2 * y)) - (View.Frame.Height / 12));

                    // Define inital sparks with location and alpha
                    var sprite = new SparkNode("spark")
                    {
                        Position = location,
                        XScale   = 1.6f,
                        YScale   = 1.6f,
                        Alpha    = 0.3f
                    };

                    // Set the Center for the node
                    sprite.CenterOfNode      = location;
                    sprite.CenterOfNodeFixed = location;

                    // Define Rotation, is zero because of the inital speed
                    var action = SKAction.RotateByAngle(NMath.PI * speed * i, 10.0);
                    sprite.RunAction(SKAction.RepeatActionForever(action));

                    // Position in comparsion to other SpriteNodes
                    sprite.ZPosition = 1;

                    // Define ParentNode, each SparkNode gets a ParentNode
                    var parent = new ParentNode("spark")
                    {
                        Position = location,
                        XScale   = 0.9f,
                        YScale   = 0.9f,
                        Alpha    = 0.3f
                    };

                    // Set the Center for the node
                    parent.CenterOfNode      = location;
                    parent.CenterOfNodeFixed = location;

                    // Define Rotation, is zero because of the inital speed
                    var paction = SKAction.RotateByAngle(NMath.PI * speed * i, 10.0);
                    parent.RunAction(SKAction.RepeatActionForever(paction));

                    // Position in comparsion to other SpriteNodes
                    parent.ZPosition = 1;

                    // Add the SparkNode to the scene
                    AddChild(sprite);

                    // Add the ParentNode to the SparkNode
                    sprite.ParentNode = parent;

                    // Add the ParentNode to the scene
                    AddChild(parent);
                }
            }
            // Do first update of the all sparks, that they will have a base movement
            UpdateSparks(3, true, true, 4, false);
        }