Esempio n. 1
0
        private void Draw(SpriteBatch spriteBatch, Camera cam, Sprite sprite, DeformableSprite deformableSprite, Vector2[,] currentSpriteDeformation, Color color)
        {
            if (sprite == null && deformableSprite == null)
            {
                return;
            }
            if (color.A == 0)
            {
                return;
            }

            float rotation = 0.0f;

            if (!Prefab.DisableRotation)
            {
                rotation = MathUtils.VectorToAngle(new Vector2(velocity.X, -velocity.Y));
                if (velocity.X < 0.0f)
                {
                    rotation -= MathHelper.Pi;
                }
            }

            drawPosition = GetDrawPosition(cam);

            float scale = GetScale();

            sprite?.Draw(spriteBatch,
                         new Vector2(drawPosition.X, -drawPosition.Y),
                         color,
                         rotation,
                         scale,
                         Prefab.DisableFlipping || velocity.X > 0.0f ? SpriteEffects.None : SpriteEffects.FlipHorizontally,
                         Math.Min(depth / MaxDepth, 1.0f));

            if (deformableSprite != null)
            {
                if (currentSpriteDeformation != null)
                {
                    deformableSprite.Deform(currentSpriteDeformation);
                }
                else
                {
                    deformableSprite.Reset();
                }
                deformableSprite?.Draw(cam,
                                       new Vector3(drawPosition.X, drawPosition.Y, Math.Min(depth / 10000.0f, 1.0f)),
                                       deformableSprite.Origin,
                                       rotation,
                                       Vector2.One * scale,
                                       color,
                                       mirror: Prefab.DisableFlipping || velocity.X <= 0.0f);
            }
        }