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); } } }
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); } } }
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)); }); }
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); }
// 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 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 } }
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(); }); }
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 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; }
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); }
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); }
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); }
// 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; }