Ejemplo n.º 1
0
        public void DrawDebugPoint(SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, DrawableRectangle point, Vector2 position, Vector2 scale)
        {
            var dynamicTexture = atlas.GetTexture(TextureName);

            if (dynamicTexture == null)
            {
                return;
            }

            var source = dynamicTexture.Source;

            var parent = (Matrix.Identity * Matrix.CreateScale(scale.X, scale.Y, 1f) * Matrix.CreateTranslation(position.X, position.Y, 0f));

            Matrix globalTransform = Matrix.CreateTranslation(Position.X, Position.Y, 0f) * parent;

            Vector2 lposition, lscale;
            float   lrotation;

            DecomposeMatrix(ref globalTransform, out lposition, out lrotation, out lscale);


            point.X = (int)lposition.X - point.Width / 2;
            point.Y = (int)lposition.Y - point.Height / 2;

            point.Draw(spriteBatch);
        }
Ejemplo n.º 2
0
        public void Draw(SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, Color color, bool flipped = false)
        {
            var dynamicTexture = atlas.GetTexture(TextureName);

            if (dynamicTexture == null)
            {
                return;
            }

            var     source   = dynamicTexture.Source;
            Vector2 position = Position;
            float   rotation = Rotation;

            if (flipped)
            {
                rotation   *= -1f;
                position.X *= -1f;
            }

            var originInPixels = new Vector2 {
                X = source.Width * Origin.X, Y = source.Height * Origin.Y
            };

            var flip = Flipped ? (!flipped) : (flipped);

            spriteBatch.Draw(
                dynamicTexture.Texture,
                position,
                source,
                color,
                rotation,
                originInPixels,
                Scale,
                flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
                0f);
        }
Ejemplo n.º 3
0
        public void Draw(SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, Vector2 position, Vector2 scale, Color color, bool flipped = false)
        {
            var dynamicTexture = atlas.GetTexture(TextureName);

            if (dynamicTexture == null)
            {
                return;
            }

            var source = dynamicTexture.Source;

            var parent = (Matrix.Identity * Matrix.CreateScale(scale.X, scale.Y, 1f) * Matrix.CreateTranslation(position.X, position.Y, 0f));

            Matrix globalTransform = GetLocalTransform(source, flipped) * parent;

            Vector2 lposition, lscale;
            float   lrotation;

            DecomposeMatrix(ref globalTransform, out lposition, out lrotation, out lscale);

            float rot = Rotation;

            if (flipped)
            {
                //lposition.X *= -1f;
                rot *= -1f;
            }

            var originInPixels = new Vector2();

            originInPixels.X = source.Width * Origin.X;
            originInPixels.Y = source.Height * Origin.Y;

            var flip = this.Flipped ? (!flipped) : (flipped);


            // IT works properly now. We just have to "rotate" the scaling, so that it scales rotated properly

            spriteBatch.Draw(
                dynamicTexture.Texture,
                lposition,
                source,
                Color.White,
                rot,
                originInPixels,
                Scale * scale,
                flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
                0.0f);

            /*
             *
             * Vector2 scaleFactor = Scale * scale;
             *
             * var originInPixels = new Vector2();
             * originInPixels.X = source.Width * Origin.X;
             * originInPixels.Y = source.Height * Origin.Y;
             *
             * var flip = this.Flipped ? (!flipped) : (flipped);
             *
             * Vector2 pos = Position ;
             *
             * float rot = Rotation;
             *
             * if (flipped)
             * {
             *  pos.X *= -1f;
             *  rot *= -1f;
             * }
             *
             *
             * spriteBatch.Draw(
             *  dynamicTexture.Texture,
             *  position + ScaleTargetPosition(pos, Vector2.Zero, scaleFactor),
             *  source,
             *  color,
             *  rot,
             *  originInPixels,
             *  scaleFactor,
             *  flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
             *  0f);
             * */
        }