예제 #1
0
파일: Frame.cs 프로젝트: eriksk/skoggylib
 public void DrawDebugPoints(SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, DrawableRectangle point, Vector2 position, Vector2 scale)
 {
     foreach (var part in Parts)
     {
         part.DrawDebugPoint(spriteBatch, atlas, point, position, scale);
     }
 }
예제 #2
0
 public void Draw(SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, List <Frame> frames, Vector2 position, Vector2 scale, Color color, bool flipped)
 {
     if (_keyFrames.Count > 0 && CurrentFrame != null)
     {
         CurrentFrame.Draw(spriteBatch, atlas, frames, position, scale, color, flipped);
     }
 }
예제 #3
0
파일: Frame.cs 프로젝트: eriksk/skoggylib
 public void Draw(SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, Vector2 position, Vector2 scale, Color color, bool flipped = false)
 {
     foreach (var part in Parts)
     {
         part.Draw(spriteBatch, atlas, position, scale, color, flipped);
     }
 }
예제 #4
0
 public void DrawDebugPoints(List <Frame> frames, SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, DrawableRectangle point, Vector2 position, Vector2 scale)
 {
     if (_keyFrames.Count > 0 && CurrentFrame != null)
     {
         CurrentFrame.DrawDebugPoints(frames, spriteBatch, atlas, point, position, scale);
     }
 }
예제 #5
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);
        }
예제 #6
0
 public void Draw(SpriteBatch spriteBatch, Matrix view, DynamicTextureAtlasManager atlas, List <Frame> frames, Color color, bool flipped)
 {
     if (_keyFrames.Count > 0 && CurrentFrame != null)
     {
         spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, CreateRenderMatrix() * view);
         CurrentFrame.Draw(spriteBatch, atlas, frames, color, flipped);
         spriteBatch.End();
     }
 }
예제 #7
0
        public void Draw(SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, List <Frame> frames, Vector2 position, Vector2 scale, Color color, bool flipped = false)
        {
            var frame = GetFrame(frames);

            if (frame == null)
            {
                return;
            }
            frame.Draw(spriteBatch, atlas, position, scale, color, flipped);
        }
예제 #8
0
        public void DrawDebugPoints(List <Frame> frames, SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, DrawableRectangle point, Vector2 position, Vector2 scale)
        {
            var frame = GetFrame(frames);

            if (frame == null)
            {
                return;
            }

            frame.DrawDebugPoints(spriteBatch, atlas, point, position, scale);
        }
예제 #9
0
        public void DrawInterpolated(SpriteBatch spriteBatch, Matrix view, DynamicTextureAtlasManager atlas, List <Frame> frames, Color color, bool flipped)
        {
            if (_keyFrames.Count > 0 && CurrentFrame != null)
            {
                Interpolation interpolation = Interpolation.Linear;
                switch (AnimationInterpolationType)
                {
                case AnimationInterpolationType.Linear:
                    break;

                case AnimationInterpolationType.Smooth:
                    interpolation = Interpolation.Pow2;
                    break;
                }

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, CreateRenderMatrix() * view);
                CurrentFrame.DrawInterpolated(interpolation, FrameProgress, NextFrame, spriteBatch, atlas, frames, color, flipped);
                spriteBatch.End();
            }
        }
예제 #10
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);
        }
예제 #11
0
        public void DrawInterpolated(Interpolation interpolation, float progress, KeyFrame next, SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, List <Frame> frames, Color color, bool flipped)
        {
            var frame     = GetFrame(frames);
            var nextFrame = next.GetFrame(frames);

            if (frame == null)
            {
                return;
            }
            if (nextFrame == null)
            {
                return;
            }
            if (frame.Parts.Count != nextFrame.Parts.Count)
            {
                return;
            }

            frame.DrawInterpolated(interpolation, progress, nextFrame, spriteBatch, atlas, frame, color, flipped);
        }
예제 #12
0
파일: Frame.cs 프로젝트: eriksk/skoggylib
        public void DrawInterpolated(Interpolation interpolation, float progress, Frame next, SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, Frame frame, Color color, bool flipped)
        {
            for (int i = 0; i < Parts.Count; i++)
            {
                var part       = Parts[i];
                var targetPart = next.Parts[i];

                part.DrawAt(
                    new Vector2(
                        interpolation.Apply(part.Position.X, targetPart.Position.X, progress),
                        interpolation.Apply(part.Position.Y, targetPart.Position.Y, progress)),
                    Utils.MathUtils.AngleLerp(interpolation, part.Rotation, targetPart.Rotation, progress),
                    spriteBatch,
                    atlas,
                    color,
                    flipped);
            }
        }
예제 #13
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);
             * */
        }