Ejemplo n.º 1
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // Called when a touch begins

            // control player motion
            var moveRight = SKAction.RepeatActionForever(SKAction.MoveBy(75.0f, 0, 2.0f));
            var moveLeft  = SKAction.RepeatActionForever(SKAction.MoveBy(-75.0f, 0, 2.0f));

            base.TouchesBegan(touches, evt);
            var touch = (UITouch)touches.AnyObject;

            playerMove(touch);

            // detects left and right screen taps, moves player accordingly
            void playerMove(UITouch location)
            {
                if (touch.LocationInNode(this).X > (Frame.Width / 2))
                {
                    playerObject.RunAction(moveRight);
                }
                if (touch.LocationInNode(this).X < (Frame.Width / 2))
                {
                    playerObject.RunAction(moveLeft);
                }
                Console.WriteLine(touch.LocationInNode(this));
            }
        }
Ejemplo n.º 2
0
        public void SetStartupPosition(nfloat width, nfloat height)
        {
            Sprite.Position = new CGPoint(width / 2.5, height / 2);
            var action = SKAction.MoveBy(0, GRAVITY, 1);

            Sprite.RunAction(SKAction.RepeatActionForever(action));
        }
        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));
                }
            }
        }
Ejemplo n.º 4
0
        protected virtual void CreateBullet(double offset)
        {
            var laserBeam = new PurpleLaser();

            laserBeam.Node.ZRotation =
                (nfloat)(owner.CurrentRotation + laserBeam.DefaultRotation);

            double radius = offset;

            double x = owner.Node.Position.X +
                       radius * Math.Cos(owner.CurrentRotation + Math.PI / 2);

            double y = owner.Node.Position.Y +
                       radius * Math.Sin(owner.CurrentRotation + Math.PI / 2);

            var finalPoint = new CGPoint(x, y);

            laserBeam.Node.Position = finalPoint;

            owner.Node.Scene?.AddChild(laserBeam.Node);

            owner.Controller.BulletsInScene.Add(laserBeam);

            laserBeam.Node.RunAction(SKAction.RepeatActionForever(CreateShootAction()));
        }
Ejemplo n.º 5
0
        public void ShowScanAction()
        {
            var size = base.Size;

            _scanText1 = new SKLabelNode("AppleSDGothicNeo-Regular")
            {
                Text     = "Move your phone",
                FontSize = 30,
                Position = new CGPoint(size.Width / 2, 100),
                Color    = UIColor.White,
            };
            AddChild(_scanText1);

            _scanText2 = new SKLabelNode("AppleSDGothicNeo-Regular")
            {
                Text     = "to find a surface",
                FontSize = 30,
                Position = new CGPoint(size.Width / 2, 70),
                Color    = UIColor.White,
            };
            AddChild(_scanText2);

            _phone          = SKSpriteNode.FromImageNamed("phone_scaled");
            _phone.Position = new CGPoint(size.Width / 2, 190);

            var circle        = UIBezierPath.FromRoundedRect(new CGRect(new CGPoint(size.Width / 2 - 20, 190), new CGSize(40, 40)), 20);
            var moveAlongPath = SKAction.RepeatActionForever(SKAction.FollowPath(circle.CGPath, false, false, 2.0));

            _phone.RunAction(moveAlongPath);

            AddChild(_phone);

            ScanActionShowing  = true;
            ScanActionFinished = false;
        }
Ejemplo n.º 6
0
        // definition of player walking animation
        void animatePlayer()
        {
            var textures = Enumerable.Range(1, 4).Select(
                (i) => SKTexture.FromImageNamed(String.Format("Stumbler-{0}", i))).ToArray();

            playerAnimate = SKAction.RepeatActionForever(SKAction.AnimateWithTextures(textures, 0.1));
            playerObject.RunAction(playerAnimate);
        }
Ejemplo n.º 7
0
        void animateobstacle4()
        {
            var textures = Enumerable.Range(1, 4).Select(
                (i) => SKTexture.FromImageNamed(String.Format("trash-{0}", i))).ToArray();

            obstacleflame4 = SKAction.RepeatActionForever(SKAction.AnimateWithTextures(textures, 0.1));
            obstacle4.RunAction(obstacleflame4);
        }
Ejemplo n.º 8
0
        void animateEnemy()
        {
            var textures = Enumerable.Range(1, 4).Select(
                (i) => SKTexture.FromImageNamed(String.Format("walker-{0}", i))).ToArray();

            enemyAnimate = SKAction.RepeatActionForever(SKAction.AnimateWithTextures(textures, 0.1));
            enemy.RunAction(enemyAnimate);
        }
Ejemplo n.º 9
0
        protected override void Move()
        {
            var action1     = SKAction.MoveBy(-50, 75, 0.5);
            var action2     = SKAction.MoveBy(-50, -75, 0.5);
            var seq         = SKAction.Sequence(action1, action2);
            var finalAction = SKAction.RepeatActionForever(seq);

            Node.RunAction(finalAction);
        }
Ejemplo n.º 10
0
        public void textScaling(SKLabelNode scaled)
        {
            var up = SKAction.ScaleBy(1.2f, 0.8f);
            //var down = SKAction.ScaleBy (0.8f, 0.5f);
            var seq  = SKAction.Sequence(new SKAction[] { up, up.ReversedAction });        //({up,down});
            var fort = SKAction.RepeatActionForever(seq);

            scaled.RunAction(fort);
        }
Ejemplo n.º 11
0
        // Add Heartbeat Animation to parent node
        private void AddHeartbeat(double tempWait)
        {
            double   wait     = tempWait - 1;
            SKAction sleep    = SKAction.WaitForDuration(wait);
            SKAction sizeUp   = SKAction.ScaleTo(1.2f, 0.1f);
            SKAction sizeDown = SKAction.ScaleTo(0.9f, 0.1f);
            var      sequence = SKAction.Sequence(sleep, sizeUp, sizeDown);

            RunAction(SKAction.RepeatActionForever(sequence));
        }
Ejemplo n.º 12
0
        // Set exactly the same animation of related spark node
        public void MoveAnimation(SKAction sequence, double pointSpeed1)
        {
            // Remove All Actions from that node
            RemoveAllActions();
            RunAction(SKAction.RepeatActionForever(sequence));

            // Set default texture
            ChangeTexture();
            AddHeartbeat(pointSpeed1);
        }
Ejemplo n.º 13
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)));
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        SKAction GetResizeAction(SKTexture texture)
        {
            SKAction sequence = SKAction.Sequence(
                SKAction.WaitForDuration(1.0f),
                SKAction.ResizeTo(192.0f, 192.0f, 1.0f),
                SKAction.WaitForDuration(1.0f),
                SKAction.ResizeTo(128.0f, 192.0f, 1.0f),
                SKAction.WaitForDuration(1.0f),
                SKAction.ResizeTo(256.0f, 128.0f, 1.0f),
                SKAction.WaitForDuration(1.0f),
                SKAction.ResizeTo(texture.Size, 1.0f)
                );

            return(SKAction.RepeatActionForever(sequence));
        }
Ejemplo n.º 16
0
        public void PlayMusic(string soundFileName)
        {
            if (soundFileName == null)
            {
                return;
            }

            if (GameUIScene.GetActionForKey(soundFileName) != null)
            {
                return;
            }

            string   path         = string.Format("Sounds/{0}", soundFileName);
            SKAction repeatAction = SKAction.RepeatActionForever(SKAction.PlaySoundFileNamed(path, true));

            GameUIScene.RunAction(repeatAction, soundFileName);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        public void EnableMove(double speedSec)
        {
            // Set size and speed
            SpeedLocal = speedSec;
            SizeLocal  = 2f;

            // Define Line Node Movement
            SKAction scaleUp           = SKAction.ScaleYTo(SizeLocal, SpeedLocal);
            SKAction scaleUpWaveUp     = SKAction.ScaleYTo(SizeLocal + 0.3f, 0.1);
            SKAction scaleUpWaveDown   = SKAction.ScaleYTo(SizeLocal, 0.1);
            SKAction scaleDown         = SKAction.ScaleYTo(0.5f, SpeedLocal);
            SKAction scaleDownWaveDown = SKAction.ScaleYTo(0.5f - 0.3f, 0.1);
            SKAction scaleDownWaveUp   = SKAction.ScaleYTo(0.5f, 0.1);
            SKAction scaleSeq          = SKAction.Sequence(scaleUp, scaleUpWaveUp, scaleUpWaveDown, scaleDown, scaleDownWaveDown, scaleDownWaveUp);

            RunAction(SKAction.RepeatActionForever(scaleSeq));
        }
Ejemplo n.º 19
0
        public override void MouseDown(NSEvent theEvent)
        {
            // Called when a mouse click occurs

            var          location = theEvent.LocationInNode(this);
            SKSpriteNode sprite   = SKSpriteNode.FromImageNamed("person");

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

            sprite.Position = location;
            sprite.SetScale(10);

            var action = SKAction.MoveBy(2, 2, 0.1);

            sprite.RunAction(SKAction.RepeatActionForever(action));
            //sprite.RunAction(SKAction.RepeatActionForever(action));
            AddChild(sprite);
        }
        protected override void CreateSceneContents()
        {
            base.CreateSceneContents();

            // no point in recomputing constant values each time
            var half_range = range / 2.0f;

            basex = (float)Scene.Frame.GetMidX() - half_range;
            basey = (float)Scene.Frame.GetMidY() - half_range;

            Scene.AddDescription("These textured sprite nodes are combined using an additive blend",
                                 new CGPoint(Scene.Frame.GetMidX(), 100));

            Scene.RunAction(SKAction.RepeatActionForever(SKAction.Sequence(
                                                             SKAction.Run(AddLight),
                                                             SKAction.WaitForDuration(0.5f, 0.1f)
                                                             )));
        }
Ejemplo n.º 21
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));
     }
 }
Ejemplo n.º 22
0
        void UpdateCharacterAnimation()
        {
            int realDirection = (Direction == Direction.North || Direction == Direction.West) ? 3 : 1;

            if (walking)
            {
                Sprite.RemoveActionForKey("standingAction");

                SKAction walkAction = (realDirection == 1) ? walkSouthEastAction : walkNorthWestAction;
                Sprite.RunAction(SKAction.RepeatActionForever(walkAction), "standingAction");
            }
            else
            {
                Sprite.RemoveActionForKey("standingAction");
                SKAction idleAction = (realDirection == 1) ? idleSouthEastAction : idleNorthWestAction;
                Sprite.RunAction(idleAction, "standingAction");
            }
        }
Ejemplo n.º 23
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;
            }
        }
Ejemplo n.º 24
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);
            }
        }
Ejemplo n.º 25
0
        public override void KeyUp(NSEvent theEvent)
        {
            // Called when a key is

            var location = theEvent.LocationInNode(this);

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

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

            var action = SKAction.MoveBy(2, 2, 0.1);

            //SKAction OutofBounds = SKAction.RemoveFromParent();

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

            AddChild(sprite);
        }
Ejemplo n.º 26
0
        public void SetExactUpdatedValues(nfloat speedLocal, nfloat sizeLocal)
        {
            SpeedLocal = speedLocal;
            SizeLocal  = sizeLocal;

            // Updated actions
            RemoveAllActions();

            // One Time move to default size
            //RunAction(SKAction.ScaleYTo(0.5f, 0.1));

            SKAction scaleUp           = SKAction.ScaleYTo(SizeLocal, SpeedLocal);
            SKAction scaleUpWaveUp     = SKAction.ScaleYTo(SizeLocal + 0.3f, 0.1);
            SKAction scaleUpWaveDown   = SKAction.ScaleYTo(SizeLocal, 0.1);
            SKAction scaleDown         = SKAction.ScaleYTo(0.5f, SpeedLocal);
            SKAction scaleDownWaveDown = SKAction.ScaleYTo(0.5f - 0.3f, 0.1);
            SKAction scaleDownWaveUp   = SKAction.ScaleYTo(0.5f, 0.1);
            SKAction scaleSeq          = SKAction.Sequence(scaleUp, scaleUpWaveUp, scaleUpWaveDown, scaleDown, scaleDownWaveDown, scaleDownWaveUp);

            RunAction(SKAction.RepeatActionForever(scaleSeq));
        }
Ejemplo n.º 27
0
        public Player(nfloat width, nfloat height)
        {
            Sprite = new SKSpriteNode("Bird")
            {
                XScale   = 0.1f,
                YScale   = 0.1f,
                Position = new CGPoint(width / 2.5, height / 2)
            };

            var action = SKAction.MoveBy(0, GRAVITY, 1);

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

            Sprite.PhysicsBody = SKPhysicsBody.Create(Sprite.Texture, Sprite.Size);
            Sprite.PhysicsBody.AffectedByGravity             = false;
            Sprite.PhysicsBody.UsesPreciseCollisionDetection = true;
            Sprite.PhysicsBody.CategoryBitMask    = (uint)PhysicsCategoryEnum.Player;
            Sprite.PhysicsBody.CollisionBitMask   = (uint)(PhysicsCategoryEnum.Player | PhysicsCategoryEnum.Pipe);
            Sprite.PhysicsBody.ContactTestBitMask = (uint)(PhysicsCategoryEnum.Player | PhysicsCategoryEnum.Pipe);;
            Sprite.PhysicsBody.Mass = 0.1f;
        }
        protected override void CreateSceneContents()
        {
            base.CreateSceneContents();

            SKTexture[] walkFrames = LoadFrames("Art/warrior_walk_", 28);

            SKSpriteNode sprite = new SKSpriteNode(walkFrames [0])
            {
                Position = new CGPoint(Scene.Frame.GetMidX(), Scene.Frame.GetMidY())
            };

            Scene.AddChild(sprite);

            //Cycle through the frame
            var animation = SKAction.AnimateWithTextures(walkFrames, 1.0f / 28, true, false);

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

            Scene.AddDescription("This sprite is animating through a series of texture images.",
                                 new CGPoint(Scene.Frame.GetMidX(), 100));
        }
Ejemplo n.º 29
0
        // Set Animation of current parent node
        public void MoveAnimation(int disturbFactor, int newX, int newX1, int newX2, int newX3, int newX4, int newY, int newY1, int newY2, int newY3, int newY4, double pointSpeed1, double pointSpeed2, double pointSpeed3, double pointSpeed4, double pointSpeed5, bool vibrate)
        {
            // Remove All Actions from that node
            RemoveAllActions();

            // Set actions similar to related spark node's actions but add the disturb factor to the movement
            SKAction action1  = SKAction.MoveTo(new CGPoint(newX + disturbFactor, newY + disturbFactor), pointSpeed1);
            SKAction action2  = SKAction.MoveTo(new CGPoint(newX1 - disturbFactor, newY1 + disturbFactor), pointSpeed2);
            SKAction action3  = SKAction.MoveTo(new CGPoint(newX2 + disturbFactor, newY2 - disturbFactor), pointSpeed3);
            SKAction action4  = SKAction.MoveTo(new CGPoint(newX3 + disturbFactor, newY3 + disturbFactor), pointSpeed4);
            SKAction action5  = SKAction.MoveTo(new CGPoint(newX4, newY4), pointSpeed5);
            var      sequence = SKAction.Sequence(action1, action2, action3, action4, action5);

            // Repeat following the five routes
            RunAction(SKAction.RepeatActionForever(sequence));

            // Change texture
            ChangeTexture(vibrate, pointSpeed1);

            // Add Heartbeat
            AddHeartbeat(pointSpeed1);
        }
        SKAction NewAnimateAnchorAction()
        {
            SKAction moveAnchorRight = SKAction.CustomActionWithDuration(1.0f, (node, elapsedTime) => {
                (node as SKSpriteNode).AnchorPoint = new CGPoint(elapsedTime, 0.0f);
            });

            SKAction moveAnchorUp = SKAction.CustomActionWithDuration(1.0f, (node, elapsedTime) => {
                (node as SKSpriteNode).AnchorPoint = new CGPoint(1.0f, elapsedTime);
            });

            SKAction moveAnchorLeft = SKAction.CustomActionWithDuration(1.0f, (node, elapsedTime) => {
                (node as SKSpriteNode).AnchorPoint = new CGPoint(1.0f - elapsedTime, 1.0f);
            });

            SKAction moveAnchorDown = SKAction.CustomActionWithDuration(1.0f, (node, elapsedTime) => {
                (node as SKSpriteNode).AnchorPoint = new CGPoint(0.0f, 1.0f - elapsedTime);
            });

            var sequence = SKAction.Sequence(moveAnchorRight, moveAnchorUp, moveAnchorLeft, moveAnchorDown);

            return(SKAction.RepeatActionForever(sequence));
        }