コード例 #1
0
		void AddAnchorDotToSprite (SKSpriteNode sprite)
		{
			CGPath myPath = new CGPath ();
			myPath.AddArc (0, 0, 10, 0, (float) Math.PI * 2, true);
			myPath.CloseSubpath ();

			SKShapeNode dot = new SKShapeNode () {
				Path = myPath,
				FillColor = UIColor.Green,
				LineWidth = 0.0f
			};
			sprite.AddChild (dot);
		}
コード例 #2
0
        void AddAnchorDotToSprite(SKSpriteNode sprite)
        {
            CGPath myPath = new CGPath();

            myPath.AddArc(0, 0, 10, 0, (float)Math.PI * 2, true);
            myPath.CloseSubpath();

            SKShapeNode dot = new SKShapeNode()
            {
                Path      = myPath,
                FillColor = UIColor.Green,
                LineWidth = 0.0f
            };

            sprite.AddChild(dot);
        }
コード例 #3
0
        /// <summary>
        /// Подсвечивание выбранного камешка заменой текстуры в спрайте
        /// </summary>
        /// <param name="gem">Камешек на подстветку.</param>
        private void ShowSelectionIndicator(Gem gem)
        {
            // Открепляем спрайт от родителя, если он есть
            if (selectedSprite.Parent != null)
            {
                selectedSprite.RemoveFromParent();
            }

            SKSpriteNode sprite  = gem.Sprite;
            SKTexture    texture = SKTexture.FromImageNamed(gem.GetSelectedSpriteName());

            selectedSprite.Size = new CGSize(gemCellWidth, gemCellHeight);
            selectedSprite.RunAction(SKAction.SetTexture(texture));

            // "Подсветка" добавляется в качестве потомка к основному спрайту камешка
            sprite.AddChild(selectedSprite);
            selectedSprite.Alpha = 1.0f;
        }
コード例 #4
0
ファイル: BoingScene.cs プロジェクト: Krumelur/KSBoingBall
        /// <summary>
        /// Initializes a new instance of the <see cref="Boing.BoingScene"/> class.
        /// </summary>
        /// <param name="size">Size of the scene in screen units.</param>
        public BoingScene(SizeF size)
            : base(size)
        {
            this.ScaleMode = SKSceneScaleMode.AspectFill;

            // We're true retro fans, so let's use the correct background color of the Amiga original version.
            this.BackgroundColor = UIColor.FromRGB (0, 0, 0);

            // Create the background grid and add it to the center of the scene.
            var gridNode = CreateBackgroundNode (this.Frame.Size);
            gridNode.Position = new PointF (0, 0);
            this.AddChild (gridNode);

            // Create our bouncing ball sprite.
            this.ballNode = CreateBallNode (true);
            // Add the ball to the scene.
            this.AddChild (this.ballNode);

            // Place the ball in the center of the screen to start.
            this.ballNode.Position = new PointF (this.Frame.Width * .5f, this.Frame.Height - this.ballNode.Frame.Height * .5f);

            // Create a shadow version of the ball. This does not have physics and gets repositioned whenever the ball itself has moved.
            var ballShadowNode = CreateBallNode (false);
            ballShadowNode.Alpha = 0.8f;
            ballShadowNode.Color = UIColor.Black;
            ballShadowNode.ColorBlendFactor = 0.8f;
            ballShadowNode.Position = new PointF (SHADOW_OFFSET, -SHADOW_OFFSET);
            ballShadowNode.ZPosition = this.ballNode.ZPosition - 1;
            // Add the shadow as a child to the ball.
            ballNode.AddChild (ballShadowNode);

            // Let our scene have some gravity that is way lower then real earth's gravity, so the ball bounces nice and slowly.
            this.PhysicsWorld.Gravity = new CGVector (0, -1.5f);

            // Create some walls around the scene to make the ball bounce.
            this.PhysicsBody = SKPhysicsBody.BodyWithEdgeLoopFromRect (this.Frame);
            // Let the collission detection system know that this is a wall.
            this.PhysicsBody.SetCategoryBitMask (CONTACT_BITS.Wall);

            // Xamarin nicely wraps the SKPhysicsWorldDelegate protocol into C# events.
            this.PhysicsWorld.DidBeginContact += this.HandleDidBeginContact;

            // And for fancyness: let it snow! This demonstrated how to easily load a particle system that was created using Xcode's particle editor.
            var particleSystem = NSKeyedUnarchiver.UnarchiveFile ("./assets/SnowParticles.sks") as SKEmitterNode;
            particleSystem.Position = new PointF (this.Frame.Width * .5f, this.Frame.Height);
            particleSystem.Name = "SnowParticle";
            this.particleRate = particleSystem.ParticleBirthRate;
            // Turn snow off initially.
            particleSystem.ParticleBirthRate = 0;
            particleSystem.ParticleTexture = SKTexture.FromImageNamed ("./assets/spark.png");
            this.AddChild(particleSystem);

            // Init ramdomizer.
            this.rand = new Random ();
        }