Beispiel #1
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            this.sceneView.Session.Run(new ARWorldTrackingConfiguration
            {
                AutoFocusEnabled       = true,
                LightEstimationEnabled = true,
                WorldAlignment         = ARWorldAlignment.Gravity
            }, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);

            //var videoNode = new SKVideoNode("Videos/big-buck-bunny-wide.mp4");
            NSUrl videoUrl  = new NSUrl("https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4");
            var   videoNode = new SKVideoNode(videoUrl);

            // Without this the video will be inverted upside down and back to front
            videoNode.YScale = -1;
            videoNode.Play();

            var videoScene = new SKScene();

            videoScene.Size      = new CoreGraphics.CGSize(416, 240);
            videoScene.ScaleMode = SKSceneScaleMode.AspectFill;
            videoNode.Position   = new CoreGraphics.CGPoint(videoScene.Size.Width / 2, videoScene.Size.Height / 2);
            videoScene.AddChild(videoNode);

            // These are set to be the same aspect ratio as the video itself (1.77 in this case)
            var   width     = 0.5f;
            float length    = (float)((width * videoScene.Size.Height) / videoScene.Size.Width);
            var   planeNode = new PlaneNode(width, length, new SCNVector3(0, 0, -0.5f), videoScene);

            this.sceneView.Scene.RootNode.AddChildNode(planeNode);
        }
 protected virtual void CreateSceneContents()
 {
     Scene = new SKScene (new SizeF (1024, 768)) {
         BackgroundColor = UIColor.Black,
         ScaleMode = SKSceneScaleMode.AspectFit
     };
 }
        // Setup overlays and lookup scene objects.
        void SetupGame()
        {
            var sceneRoot = sceneInterface.Scene?.RootNode;

            if (sceneRoot == null)
            {
                throw new InvalidProgramException();
            }

            gameNodes = new GameNodes(sceneRoot);
            var gNodes = gameNodes.Value;

            gNodes.Object.Transform            = SCNMatrix4.Identity;
            gNodes.ObjectMaterial.Transparency = 0;
            gNodes.Confetti.Hidden             = true;

            var skScene = new SKScene(ContentFrame.Size)
            {
                ScaleMode = SKSceneScaleMode.ResizeFill
            };

            skScene.AddChild(gNodes.CountdownLabel);

            sceneInterface.OverlayScene = skScene;
        }
        public void Create()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Requires iOS7");
            }

            using (var s = new SKScene(new SizeF(320, 240)))
                using (var b1 = SKPhysicsBody.CreateCircularBody(1.0f))
                    using (var b2 = SKPhysicsBody.CreateCircularBody(2.0f)) {
                        // according to Apple docs we should not create this joint before adding it to a scene
                        // <quote>The body must be connected to a node that is already part of the scene’s node tree.</quote>
                        // Note that doing the same for a `SKPhysicsJointLimit` does crash
                        using (var j = SKPhysicsJointFixed.Create(b1, b2, new PointF(10, 20))) {
                            Assert.That(j.BodyA, Is.SameAs(b1), "BodyA");
                            Assert.That(j.BodyB, Is.SameAs(b2), "BodyB");

                            SKNode n1 = new SKNode();
                            n1.PhysicsBody = b1;
                            s.AddChild(n1);

                            SKNode n2 = new SKNode();
                            n2.PhysicsBody = b2;
                            s.AddChild(n2);

                            // using the default ctor (for `j`) would crash (and no way to set the PointF argument)
                            // https://bugzilla.xamarin.com/show_bug.cgi?id=14511
                            s.PhysicsWorld.AddJoint(j);
                        }
                    }
        }
Beispiel #5
0
        public void Create()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Ignore("Requires iOS7");
            }

            using (var s = new SKScene(new SizeF(320, 240)))
                using (var b1 = SKPhysicsBody.CreateCircularBody(1.0f))
                    using (var b2 = SKPhysicsBody.CreateCircularBody(2.0f)) {
                        // <quote>The body must be connected to a node that is already part of the scene’s node tree.</quote>
                        SKNode n1 = new SKNode();
                        n1.PhysicsBody = b1;
                        s.AddChild(n1);

                        SKNode n2 = new SKNode();
                        n2.PhysicsBody = b2;
                        s.AddChild(n2);

                        // if you create the SKPhysicsJointLimit *before* adding the nodes
                        // to a scene then you'll crash and burn. ref: bug #14793
                        using (var j = SKPhysicsJointLimit.Create(b1, b2, PointF.Empty, new PointF(10, 20))) {
                            Assert.That(j.BodyA, Is.SameAs(b1), "BodyA");
                            Assert.That(j.BodyB, Is.SameAs(b2), "BodyB");

                            s.PhysicsWorld.AddJoint(j);
                        }
                    }
        }
 public void DefaultCtor()
 {
     using (var Scene = new SKScene(UIScreen.MainScreen.Bounds.Size))
         using (var b = new SKSpriteNode(UIColor.Red, new CGSize(10, 10))) {
             b.PhysicsBody = new SKPhysicsBody();
             Scene.AddChild(b);              //BOOM
         }
 }
Beispiel #7
0
 protected virtual void CreateSceneContents()
 {
     Scene = new SKScene(new CGSize(1024, 768))
     {
         BackgroundColor = UIColor.Black,
         ScaleMode       = SKSceneScaleMode.AspectFit
     };
 }
        void ShowEndScreen()
        {
            gameIsComplete = true;

            // Add confettis
            SCNMatrix4 particlePosition = SCNMatrix4.CreateTranslation(0f, 8f, 0f);

            GameView.Scene.AddParticleSystem(confetti, particlePosition);

            // Congratulation title
            SKSpriteNode congrat = SKSpriteNode.FromImageNamed("Images/congratulations.png");

            congrat.Position = new CGPoint(GameView.Bounds.Width / 2, GameView.Bounds.Height / 2);
            SKScene overlay = GameView.OverlayScene;

            congrat.XScale = congrat.YScale = 0;
            congrat.Alpha  = 0;
            congrat.RunAction(SKAction.Group(new [] {
                SKAction.FadeInWithDuration(0.25),
                SKAction.Sequence(new [] {
                    SKAction.ScaleTo(.55f, 0.25),
                    SKAction.ScaleTo(.3f, 0.1),
                })
            }));

            // Panda Image
            SKSpriteNode congratPanda = SKSpriteNode.FromImageNamed("Images/congratulations_pandaMax.png");

            congratPanda.Position    = new CGPoint(GameView.Bounds.Width / 2f, GameView.Bounds.Height / 2f - 90f);
            congratPanda.AnchorPoint = new CGPoint(.5f, 0f);
            congratPanda.XScale      = congratPanda.YScale = 0f;
            congratPanda.Alpha       = 0;

            congratPanda.RunAction(SKAction.Sequence(new [] {
                SKAction.WaitForDuration(.5f),
                SKAction.Sequence(new [] {
                    SKAction.ScaleTo(.5f, 0.25),
                    SKAction.ScaleTo(.4f, 0.1)
                })
            }));

            overlay.AddChild(congratPanda);
            overlay.AddChild(congrat);

            // Stop music
            GameView.Scene.RootNode.RemoveAllAudioPlayers();

            // Play the congrat sound.
            GameView.Scene.RootNode.AddAudioPlayer(SCNAudioPlayer.FromSource(victoryMusic));

            // Animate the camera forever
            DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 1 * NanoSecondsPerSeond), () => {
                cameraYHandle.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0f, -1f, 0f, 3.0)));
                cameraXHandle.RunAction(SCNAction.RotateTo(-(float)Math.PI / 4f, 0f, 0f, 5.0));
            });
        }
Beispiel #9
0
        public PlaneNode(float width, float length, SCNVector3 position, SKScene videoScene)
        {
            var rootNode = new SCNNode
            {
                Geometry = CreateGeometry(width, length, videoScene),
                Position = position
            };

            AddChildNode(rootNode);
        }
 public void SampleFields()
 {
     using (var scene = new SKScene()) {
         using (var world = scene.PhysicsWorld) {
             var v = world.SampleFields(new Vector3(1, 2, 3));
             Assert.AreEqual(0, v.X, "#x1");
             Assert.AreEqual(0, v.Y, "#y1");
             Assert.AreEqual(0, v.Z, "#z1");
         }
     }
 }
 public void Action(SKScene sceen, CGPoint location)
 {
     node.Position = location;
     sceen.AddChild(node);
     // 繰り返しの場合
     //SKAction* forever = [SKAction repeatActionForever: walk];
     //[walker runAction:forever];
     node.RunAction(action, () =>
     {
         node.RemoveFromParent();
     });
 }
Beispiel #12
0
        private static SCNGeometry CreateGeometry(float width, float length, SKScene videoScene)
        {
            var material = new SCNMaterial();

            material.Diffuse.Contents = videoScene;
            material.DoubleSided      = true;

            var geometry = SCNPlane.Create(width, length);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Beispiel #13
0
        public GameController(SKScene scene)
        {
            Scene          = scene;
            SceneGameUnits = new List <GameUnit>();
            BulletsInScene = new List <Bullet>();
            BonusesInScene = new List <Bonus>();
            pressedKeys    = new List <ushort>();
            Hud            = new Hud(this);
            boss           = null;

            SceneUpdateDelegate  = new UpdateDelegate(CheckBulletsForActions);
            SceneUpdateDelegate += CheckUnitsForActions;
            SceneUpdateDelegate += CheckForMovingPlayer;
            SceneUpdateDelegate += CheckForEnemySpawning;
            SceneUpdateDelegate += CheckForBonusCreating;
        }
Beispiel #14
0
        public void Draw(SKScene scene, double sec)
        {
            if (_skNode == null)
            {
                _skNode = new SKSpriteNode(SKTexture.FromImageNamed("Ball"), UIColor.Clear, new CGSize(5, 5));
                scene.AddChild(_skNode);
            }

            _skNode.RunAction(SKAction.MoveTo(new CGPoint(
                                                  OffsetFromZero[0] - (OffsetFromZero[2] / Math.Sqrt(2.0)),
                                                  OffsetFromZero[1] - (OffsetFromZero[2] / Math.Sqrt(2.0))), sec));

            foreach (var child in Children)
            {
                child.Draw(scene, sec);
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.statusViewController = this.ChildViewControllers.FirstOrDefault(controller => controller is StatusViewController) as StatusViewController;

            // Configiure and present the SpriteKit scene that draws overlay content.
            var overlayScene = new SKScene {
                ScaleMode = SKSceneScaleMode.AspectFill
            };

            this.sceneView.Delegate = this;
            this.sceneView.PresentScene(overlayScene);
            this.sceneView.Session.Delegate = this;

            // Hook up status view controller callback.
            this.statusViewController.RestartExperienceHandler = () => this.RestartSession();
        }
Beispiel #16
0
        public Kuma(SKScene sceen, CGPoint location, CGSize size)
        {
            _textures = new SKTexture[ImageMax];
            for (var i = 0; i < ImageMax; i++)
            {
                _textures[i] = SKTexture.FromImageNamed(String.Format("Image{0}", i));
            }

            _node             = SKSpriteNode.FromTexture((SKTexture)_textures[0]);
            _node.AnchorPoint = new CGPoint(0, 0);
            _node.Position    = location;
            _node.Size        = size;
            _node.ZPosition   = 0;
            sceen.AddChild(_node);

            _locationX = location.X;
            _locationY = location.Y;
            _width     = size.Width;
        }
Beispiel #17
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);
        }
Beispiel #18
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            var touch = (UITouch)touches.AnyObject;

            SKScene scene = OverlayScene;
            CGPoint p     = touch.LocationInView(this);

            p = scene.ConvertPointFromView(p);
            SKNode node = scene.GetNodeAtPoint(p);

            if (node.Name == "camera")
            {
                node.RunAction(SKAction.PlaySoundFileNamed(ResourceManager.GetResourcePath("click.caf"), false));
                ChangePointOfView();
                return;
            }

            NSSet allTouches = evt.AllTouches;

            TouchesCount = (int)allTouches.Count;
        }
Beispiel #19
0
 public AgentNode(SKScene scene, float radius, CGPoint position)
 {
     InitAgent(scene, radius, position);
 }
Beispiel #20
0
 public AgentNode(SKScene scene, float radius, CGPoint position)
 {
     InitAgent (scene, radius, position);
 }
Beispiel #21
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);
        }
Beispiel #22
0
 public GamePad(SKScene scene)
 {
     _scene = scene;
 }
		// Setup overlays and lookup scene objects.
		void SetupGame ()
		{
			var sceneRoot = sceneInterface.Scene?.RootNode;
			if (sceneRoot == null)
				throw new InvalidProgramException ();

			gameNodes = new GameNodes (sceneRoot);
			var gNodes = gameNodes.Value;

			gNodes.Object.Transform = SCNMatrix4.Identity;
			gNodes.ObjectMaterial.Transparency = 0;
			gNodes.Confetti.Hidden = true;

			var skScene = new SKScene (ContentFrame.Size) {
				ScaleMode = SKSceneScaleMode.ResizeFill
			};
			skScene.AddChild (gNodes.CountdownLabel);

			sceneInterface.OverlayScene = skScene;
		}
Beispiel #24
0
        public void Setup()
        {
            nfloat w = Bounds.Width;
            nfloat h = Bounds.Height;

            if (w < h)
            {
                nfloat wTmp = w;
                w = h;
                h = wTmp;
            }

            // Setup the game overlays using SpriteKit
            SKScene skScene = SKScene.FromSize(new CGSize(w, h));

            skScene.ScaleMode = SKSceneScaleMode.ResizeFill;

            overlayGroup = SKNode.Create();
            skScene.AddChild(overlayGroup);
            overlayGroup.Position = new CGPoint(0f, h);

            // The Max icon
            SKSpriteNode sprite = SKSpriteNode.FromImageNamed("Images/MaxIcon.png");

            sprite.Position = new CGPoint(50f, -50f);

            overlayGroup.AddChild(sprite);
            sprite.XScale = sprite.YScale = 0.5f;

            for (int i = 0; i < 3; i++)
            {
                flowers [i]          = SKSpriteNode.FromImageNamed("Images/FlowerEmpty.png");
                flowers [i].Position = new CGPoint(110f + i * 40f, -50f);
                flowers [i].XScale   = flowers [i].YScale = 0.25f;
                overlayGroup.AddChild(flowers[i]);
            }

            // The peal icon and count.
            sprite          = SKSpriteNode.FromImageNamed("Images/ItemsPearl.png");
            sprite.Position = new CGPoint(110f, -100f);
            sprite.XScale   = sprite.YScale = 0.5f;
            overlayGroup.AddChild(sprite);

            pearlLabel          = SKLabelNode.FromFont("Chalkduster");
            pearlLabel.Text     = "x0";
            pearlLabel.Position = new CGPoint(152f, -113f);
            overlayGroup.AddChild(pearlLabel);

            // The D-Pad
            sprite          = SKSpriteNode.FromImageNamed("Images/dpad.png");
            sprite.Position = new CGPoint(100f, 100f);
            sprite.XScale   = sprite.YScale = 0.5f;
            skScene.AddChild(sprite);
            padRect = new CGRect(
                (sprite.Position.Y - DPAD_RADIUS) / w,
                1f - (sprite.Position.Y + DPAD_RADIUS) / h,
                2f * DPAD_RADIUS / w,
                2f * DPAD_RADIUS / h
                );

            // Assign the SpriteKit overlay to the SceneKit view.
            OverlayScene = skScene;

            // Setup the pinch gesture
            defaultFov = PointOfView.Camera.XFov;

            var pinch = new UIPinchGestureRecognizer {
                Delegate             = this,
                CancelsTouchesInView = false
            };

            pinch.AddTarget(() => PinchWithGestureRecognizer(pinch));

            AddGestureRecognizer(pinch);
        }