コード例 #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
ファイル: KeyFrameAnimation.cs プロジェクト: eriksk/skoggylib
 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
ファイル: KeyFrameAnimation.cs プロジェクト: eriksk/skoggylib
 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
ファイル: FramePart.cs プロジェクト: eriksk/skoggylib
        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
ファイル: KeyFrameAnimation.cs プロジェクト: eriksk/skoggylib
 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
ファイル: KeyFrame.cs プロジェクト: eriksk/skoggylib
        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
ファイル: KeyFrame.cs プロジェクト: eriksk/skoggylib
        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
ファイル: KeyFrameAnimation.cs プロジェクト: eriksk/skoggylib
        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
ファイル: FramePart.cs プロジェクト: eriksk/skoggylib
        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
ファイル: KeyFrame.cs プロジェクト: eriksk/skoggylib
        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
ファイル: FramePart.cs プロジェクト: eriksk/skoggylib
        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);
             * */
        }