Exemple #1
0
        protected override void Update(GameTime gameTime)
        {
            var keyboard     = Keyboard.GetState();
            var gamePadState = GamePad.GetState(PlayerIndex.One);

            if (gamePadState.Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var index = 0; index < _sprites.Length; index++)
            {
                var sprite = _sprites[index];

                if (index % 2 == 0)
                {
                    sprite.Rotation = (sprite.Rotation + MathHelper.ToRadians(0.5f)) % MathHelper.TwoPi;
                }
                else
                {
                    sprite.Rotation = (sprite.Rotation - MathHelper.ToRadians(0.5f) + MathHelper.TwoPi) % MathHelper.TwoPi;
                }

                sprite.Color = ColorHelper.FromHsl(sprite.Rotation / MathHelper.TwoPi, 0.5f, 0.3f);

                sprite.TransformMatrix = Matrix2.CreateFrom(sprite.Position, sprite.Rotation, _spriteScale, _spriteOrigin);

                _sprites[index] = sprite;
            }

            base.Update(gameTime);
        }
 /// <summary>
 ///     Draws unicode (UTF-16) characters as sprites using the specified <see cref="BitmapFont" />, text
 ///     <see cref="string" />, position <see cref="Vector2" /> and optional <see cref="Color" />, rotation
 ///     <see cref="float" />, origin <see cref="Vector2" />, scale <see cref="Vector2" /> <see cref="FlipFlags" />, and
 ///     depth <see cref="float" />.
 /// </summary>
 /// <param name="bitmapFont">The <see cref="BitmapFont" />.</param>
 /// <param name="text">The text <see cref="string" />.</param>
 /// <param name="position">The position <see cref="Vector2" />.</param>
 /// <param name="color">
 ///     The <see cref="Color" />. Use <code>null</code> to use the default
 ///     <see cref="Color.White" />.
 /// </param>
 /// <param name="rotation">
 ///     The angle <see cref="float" /> (in radians) to rotate each sprite about its <paramref name="origin" />. The default
 ///     value is <code>0f</code>.
 /// </param>
 /// <param name="origin">
 ///     The origin <see cref="Vector2" />. Use <code>null</code> to use the default
 ///     <see cref="Vector2.Zero" />.
 /// </param>
 /// <param name="scale">
 ///     The scale <see cref="Vector2" />. Use <code>null</code> to use the default
 ///     <see cref="Vector2.One" />.
 /// </param>
 /// <param name="flags">The <see cref="FlipFlags" />. The default value is <see cref="FlipFlags.None" />.</param>
 /// <param name="depth">The depth <see cref="float" />. The default value is <code>0f</code></param>
 /// <exception cref="InvalidOperationException">The <see cref="Batcher{TDrawCallInfo}.Begin(ref Matrix, ref Matrix, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect)" /> method has not been called.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="bitmapFont" /> is null or <paramref name="text" /> is null.</exception>
 public void DrawString(BitmapFont bitmapFont, string text, Vector2 position, Color?color = null,
                        float rotation  = 0f, Vector2?origin          = null, Vector2?scale = null,
                        FlipFlags flags = FlipFlags.None, float depth = 0f)
 {
     Matrix2.CreateFrom(position, rotation, scale, origin, out Matrix2 matrix);
     DrawString(bitmapFont, text, ref matrix, color, flags, depth);
 }