private void SelectNodeForTouch(PointF touchLocation)
        {
            // get the node that is on the posiion touchLocation
            SKSpriteNode touchedNode = (SKSpriteNode)this.GetNodeAtPoint(touchLocation);

            // if this is a new node being touched then stop all previous animation and set it as the selected node.
            if (this.SelectedNode != touchedNode)
            {
                if (this.SelectedNode != null)
                {
                    this.SelectedNode.RemoveAllActions();
                    this.SelectedNode.RunAction(SKAction.RotateToAngle(0.0f, 0.1));
                }

                this.SelectedNode = touchedNode;

                // if the node we've touched is an animal node then make it wiggle y0!
                if (touchedNode.Name == ANIMAL_NODE_NAME)
                {
                    SKAction sequence = SKAction.Sequence(new SKAction[] {
                        SKAction.RotateByAngle(this.DegreeToRadian(-4.0f), 0.1),
                        SKAction.RotateByAngle(0.0f, 0.1),
                        SKAction.RotateByAngle(this.DegreeToRadian(4.0f), 0.1)
                    });

                    this.SelectedNode.RunAction(SKAction.RepeatActionForever(sequence));
                }
            }
        }
        public void LeftPedal()
        {
            //1)UPDATE THE HEADING CCW
            this.Heading = (this.Heading + 5) % 360;
            var action1 = SKAction.RotateByAngle(this.Heading, 1.0);

            this.PlayerSpriteObject.RunAction(action1);
        }
        public void RightPedal()
        {
            //1)UPDATE THE HEADING CW
            this.Heading = (this.Heading - 5) % 180;//heading is in degrees
            //2)ROTATE BY THE ANGLE OF THE HEADING
            var action1 = SKAction.RotateByAngle(this.Heading, 1.0);

            //HAVE PLAYER MOVE
            this.PlayerSpriteObject.RunAction(action1);
        }
예제 #4
0
        public void ShootSpell(CGPoint position)
        {
            // Create vector of the movement
            var vector = new CGVector(position.X - Position.X, position.Y - Position.Y);

            // Create spell instance place it into the world and force it to attack
            var spell = ShotSprite.CreateShotAt(Position, SpellType.Hero);

            Parent.AddChild(spell);
            spell.AttackByVector(vector);
            spell.RunAction(SKAction.RepeatActionForever(SKAction.RotateByAngle((nfloat)6.28, 1)));
        }
예제 #5
0
        public void CreateSprite(CGPoint location)
        {
            var sprite = SKSpriteNode.FromImageNamed(NSBundle.MainBundle.PathForResource("Spaceship", "png"));

            sprite.Position = location;
            sprite.SetScale(0.5f);

            var action = SKAction.RotateByAngle(NMath.PI, 1.0);

            sprite.RunAction(SKAction.RepeatActionForever(action));

            AddChild(sprite);
        }
예제 #6
0
        public override void MouseDown(NSEvent theEvent)
        {
            // Called when a mouse click occurs

            var location = theEvent.LocationInNode(this);

            var sprite = SKSpriteNode.FromImageNamed(NSBundle.MainBundle.PathForResource("Spaceship", "png"));

            sprite.Position = location;
            sprite.SetScale(0.5f);

            var action = SKAction.RotateByAngle(NMath.PI, 1.0);

            sprite.RunAction(SKAction.RepeatActionForever(action));

            AddChild(sprite);
        }
예제 #7
0
 public Pipe(CGPoint position, bool isRotated = false)
 {
     Sprite = new SKSpriteNode("Pipe")
     {
         Position = position,
         XScale   = 0.5f,
         YScale   = 1.5f
     };
     Sprite.PhysicsBody = SKPhysicsBody.Create(Sprite.Texture, Sprite.Size);
     Sprite.PhysicsBody.AffectedByGravity             = false;
     Sprite.PhysicsBody.CategoryBitMask               = (uint)PhysicsCategoryEnum.Pipe;
     Sprite.PhysicsBody.UsesPreciseCollisionDetection = true;
     Sprite.RunAction(SKAction.RepeatActionForever(SKAction.MoveBy(-100, 0, 1)));
     if (isRotated)
     {
         Sprite.RunAction(SKAction.RotateByAngle(NMath.PI, 0));
     }
 }
예제 #8
0
        // Change Texture to disturbed texture
        public void ChangeTexture(bool disturb, double pointSpeed1)
        {
            // Default texture
            SKTexture sparkTexture3 = SKTexture.FromImageNamed("spark3");

            // Disturbed texture
            SKTexture sparkTexture4 = SKTexture.FromImageNamed("spark4");

            // Set custom fade and rotation actions
            if (disturb == true)
            {
                // Set disturbed texture
                Texture = sparkTexture4;

                // Fade Actions on the node
                // SKAction action1 = SKAction.FadeAlphaBy(-0.2f, 1);
                // SKAction action2 = SKAction.FadeAlphaBy(+0.2f, 1);
                // SKAction sequence = SKAction.Sequence(action1, action2);

                // Generated random rotation factor
                double rotateBy = rnd.NextDouble() * (2 - 1) + 1;
                RunAction(SKAction.RepeatActionForever(SKAction.RotateByAngle(NMath.PI, rotateBy)));

                // Set X Scaling related to PointSpeed1
                SKAction changeX1        = SKAction.ScaleXTo(1.1f, pointSpeed1);
                SKAction changeX2        = SKAction.ScaleXTo(0.9f, pointSpeed1);
                var      changeSequenceX = SKAction.Sequence(changeX1, changeX2);
                RunAction(SKAction.RepeatActionForever(changeSequenceX));

                // Set Y Scaling related to PointSpeed1
                SKAction changeY1        = SKAction.ScaleYTo(1.1f, pointSpeed1);
                SKAction changeY2        = SKAction.ScaleYTo(0.9f, pointSpeed1);
                var      changeSequenceY = SKAction.Sequence(changeY1, changeY2);
                RunAction(SKAction.RepeatActionForever(changeSequenceY));
            }

            // Set default texture
            else
            {
                Texture = sparkTexture3;
            }
        }
예제 #9
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // Called when a touch begins
            foreach (var touch in touches)
            {
                var location = ((UITouch)touch).LocationInNode(this);

                var sprite = new SKSpriteNode("logo")
                {
                    Position = location,
                    XScale   = 0.5f,
                    YScale   = 0.5f
                };

                var action = SKAction.RotateByAngle(NMath.PI, 1.0);

                sprite.RunAction(SKAction.RepeatActionForever(action));

                AddChild(sprite);
            }
        }
        public void Move(MoveDirection direction, double timeInterval)
        {
            var rot = ZRotation;

            SKAction action = null;
            float    x, y;

            // Build up the movement action.
            switch (direction)
            {
            case MoveDirection.Forward:
                x      = -(float)(Math.Sin(rot) * MovementSpeed * timeInterval);
                y      = (float)(Math.Cos(rot) * MovementSpeed * timeInterval);
                action = SKAction.MoveBy(x, y, timeInterval);
                break;

            case MoveDirection.Back:
                x      = (float)(Math.Sin(rot) * MovementSpeed * timeInterval);
                y      = -(float)(Math.Cos(rot) * MovementSpeed * timeInterval);
                action = SKAction.MoveBy(x, y, timeInterval);
                break;

            case MoveDirection.Left:
                action = SKAction.RotateByAngle(RotationSpeed, timeInterval);
                break;

            case MoveDirection.Right:
                action = SKAction.RotateByAngle(-RotationSpeed, timeInterval);
                break;
            }

            // Play the resulting action.
            if (action != null)
            {
                RequestedAnimation = AnimationState.Walk;
                RunAction(action);
            }
        }
예제 #11
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);
        }