Example #1
0
        public void RefreshTreeView()
        {
            mTreeView.Invoke((MethodInvoker) delegate()
            {
                AnimationFrameSave selectedAnimationFrame = SelectedState.Self.SelectedFrame;
                AnimationChainSave selectedAnimationChain = SelectedState.Self.SelectedChain;

                List <AnimationChainSave> expandedAnimationChains = new List <AnimationChainSave>();

                foreach (TreeNode treeNode in mTreeView.Nodes)
                {
                    if (treeNode.IsExpanded)
                    {
                        expandedAnimationChains.Add(treeNode.Tag as AnimationChainSave);
                    }
                }

                mTreeView.Nodes.Clear();


                if (ProjectManager.Self.AnimationChainListSave != null)
                {
                    TreeNode[] nodesToAdd = new TreeNode[ProjectManager.Self.AnimationChainListSave.AnimationChains.Count];

                    int index = 0;
                    foreach (var animationChain in ProjectManager.Self.AnimationChainListSave.AnimationChains)
                    {
                        TreeNode treeNode = new TreeNode();

                        nodesToAdd[index] = treeNode;

                        WithoutEnvokeRefreshTreeNode(treeNode, animationChain);
                        if (expandedAnimationChains.Contains(animationChain))
                        {
                            treeNode.Expand();
                        }
                        index++;
                    }

                    mTreeView.Nodes.AddRange(nodesToAdd);


                    if (selectedAnimationFrame != null)
                    {
                        SelectedState.Self.SelectedFrame = selectedAnimationFrame;
                    }
                    if (mTreeView.SelectedNode == null && selectedAnimationChain != null)
                    {
                        SelectedState.Self.SelectedChain = selectedAnimationChain;
                    }
                }
            });
        }
Example #2
0
        private AnimationFrame AnimationFrameSaveToRenderingLibraryAnimationFrame(AnimationFrameSave afs)
        {
            AnimationFrame af = new AnimationFrame();

            af.Texture = WireframeManager.Self.GetTextureForFrame(afs);

            af.FlipHorizontal  = afs.FlipHorizontal;
            af.FlipVertical    = afs.FlipVertical;
            af.SourceRectangle = GetSourceRetangleForFrame(afs, af.Texture);
            af.FrameTime       = afs.FrameLength;
            return(af);
        }
Example #3
0
        void HandleRegionChanged(object sender, EventArgs e)
        {
            AnimationFrameSave frame = SelectedState.Self.SelectedFrame;

            if (frame != null)
            {
                Texture2D texture = mControl.CurrentTexture;

                frame.LeftCoordinate   = mControl.RectangleSelector.Left / (float)texture.Width;
                frame.RightCoordinate  = mControl.RectangleSelector.Right / (float)texture.Width;
                frame.TopCoordinate    = mControl.RectangleSelector.Top / (float)texture.Height;
                frame.BottomCoordinate = mControl.RectangleSelector.Bottom / (float)texture.Height;

                TreeViewManager.Self.RefreshTreeNode(frame);
            }
            else if (SelectedState.Self.SelectedChain != null)
            {
                if (mPushedRegion != null)
                {
                    Texture2D texture = mControl.CurrentTexture;

                    int changedLeft   = FlatRedBall.Math.MathFunctions.RoundToInt(mPushedRegion.Left - mPushedRegion.OldLeft);
                    int changedTop    = FlatRedBall.Math.MathFunctions.RoundToInt(mPushedRegion.Top - mPushedRegion.OldTop);
                    int changedBottom = FlatRedBall.Math.MathFunctions.RoundToInt(mPushedRegion.Bottom - mPushedRegion.OldBottom);
                    int changedRight  = FlatRedBall.Math.MathFunctions.RoundToInt(mPushedRegion.Right - mPushedRegion.OldRight);

                    if (changedLeft != 0 || changedTop != 0 || changedRight != 0 || changedBottom != 0)
                    {
                        // only move the regions that are shown
                        foreach (var region in mControl.RectangleSelectors)
                        {
                            var frameForRegion = region.Tag as AnimationFrameSave;

                            frameForRegion.LeftCoordinate  += changedLeft / (float)texture.Width;
                            frameForRegion.RightCoordinate += changedRight / (float)texture.Width;

                            frameForRegion.TopCoordinate    += changedTop / (float)texture.Height;
                            frameForRegion.BottomCoordinate += changedBottom / (float)texture.Height;
                        }

                        UpdateSelectorsToAnimation(skipUpdatingRectangleSelector: true, texture: texture);
                        PreviewManager.Self.ReactToAnimationChainSelected();
                    }
                }
            }
            // This is causing spamming of the save - we only want to do this on a mouse click
            //if (AnimationChainChange != null)
            //{
            //    AnimationChainChange(this, null); b
            //}
            AnimationFrameChange?.Invoke(this, null);
        }
Example #4
0
        object GetPixelWidth()
        {
            AnimationFrameSave frame = Instance as AnimationFrameSave;

            if (mTexture == null)
            {
                return(0);
            }
            else
            {
                return(MathFunctions.RoundToInt(mTexture.Width * (frame.RightCoordinate - frame.LeftCoordinate)));
            }
        }
Example #5
0
        public Texture2D GetTextureForFrame(AnimationFrameSave frame)
        {
            string fileName = GetTextureFileNameForFrame(frame);


            Texture2D texture = null;

            if (!string.IsNullOrEmpty(fileName) && System.IO.File.Exists(fileName))
            {
                texture = LoaderManager.Self.LoadContent <Texture2D>(fileName);
            }
            return(texture);
        }
Example #6
0
        object GetTileX()
        {
            AnimationFrameSave frame = Instance as AnimationFrameSave;

            if (mTexture == null || TileMapInformation == null || TileMapInformation.TileWidth == 0)
            {
                return(0);
            }
            else
            {
                return(MathFunctions.RoundToInt((mTexture.Width * frame.LeftCoordinate) / TileMapInformation.TileWidth));
            }
        }
Example #7
0
        object GetPixelHeight()
        {
            AnimationFrameSave frame = Instance as AnimationFrameSave;

            if (mTexture == null)
            {
                return(0);
            }
            else
            {
                return(MathFunctions.RoundToInt(mTexture.Height * (frame.BottomCoordinate - frame.TopCoordinate)));
            }
        }
Example #8
0
        object GetTileY()
        {
            AnimationFrameSave frame = Instance as AnimationFrameSave;

            if (mTexture == null || TileMapInformation == null || TileMapInformation.TileHeight == 0)
            {
                return(0);
            }
            else
            {
                return(MathFunctions.RoundToInt((mTexture.Height * frame.TopCoordinate) / TileMapInformation.TileHeight));
            }
        }
Example #9
0
        private void UpdateSpriteToAnimationFrame()
        {
            AnimationFrameSave afs = SelectedState.Self.SelectedFrame;

            if (afs != null)
            {
                RenderingLibrary.Graphics.Sprite sprite = mSprite;
                sprite.Visible = true;
                UpdateSpriteToAnimationFrame(afs, sprite);
            }

            UpdateOnionSkinSprites();
        }
Example #10
0
        void HandleRegionChanged(object sender, EventArgs e)
        {
            AnimationFrameSave frame = SelectedState.Self.SelectedFrame;

            if (frame != null)
            {
                Texture2D texture = mControl.CurrentTexture;

                frame.LeftCoordinate   = mControl.RectangleSelector.Left / (float)texture.Width;
                frame.RightCoordinate  = mControl.RectangleSelector.Right / (float)texture.Width;
                frame.TopCoordinate    = mControl.RectangleSelector.Top / (float)texture.Height;
                frame.BottomCoordinate = mControl.RectangleSelector.Bottom / (float)texture.Height;

                TreeViewManager.Self.RefreshTreeNode(frame);
            }
            else if (SelectedState.Self.SelectedChain != null)
            {
                if (mPushedRegion != null)
                {
                    Texture2D texture = mControl.CurrentTexture;

                    int changedLeft   = FlatRedBall.Math.MathFunctions.RoundToInt(mPushedRegion.Left - mPushedRegion.OldLeft);
                    int changedTop    = FlatRedBall.Math.MathFunctions.RoundToInt(mPushedRegion.Top - mPushedRegion.OldTop);
                    int changedBottom = FlatRedBall.Math.MathFunctions.RoundToInt(mPushedRegion.Bottom - mPushedRegion.OldBottom);
                    int changedRight  = FlatRedBall.Math.MathFunctions.RoundToInt(mPushedRegion.Right - mPushedRegion.OldRight);

                    foreach (var containedFrame in SelectedState.Self.SelectedChain.Frames)
                    {
                        // shift this by pixels!

                        containedFrame.LeftCoordinate  += changedLeft / (float)texture.Width;
                        containedFrame.RightCoordinate += changedRight / (float)texture.Width;

                        containedFrame.TopCoordinate    += changedTop / (float)texture.Height;
                        containedFrame.BottomCoordinate += changedBottom / (float)texture.Height;
                    }

                    UpdateSelectorsToAnimation(skipPushed: true, texture: texture);
                    PreviewManager.Self.ReactToAnimationChainSelected();
                }
            }
            // This is causing spamming of the save - we only want to do this on a mouse click
            //if (AnimationChainChange != null)
            //{
            //    AnimationChainChange(this, null);
            //}
            if (AnimationFrameChange != null)
            {
                AnimationFrameChange(this, null);
            }
        }
Example #11
0
        public void SetTileX(AnimationFrameSave frame, int valueAsInt)
        {
            if (frame == null)
            {
                throw new ArgumentNullException(nameof(frame));
            }
            TileMapInformation information = TileMapInformation;

            if (information != null && mTexture != null)
            {
                int pixelPosition = valueAsInt * information.TileWidth;
                frame.LeftCoordinate  = pixelPosition / (float)mTexture.Width;
                frame.RightCoordinate = frame.LeftCoordinate + (information.TileWidth / (float)mTexture.Width);
            }
        }
Example #12
0
        public void SetTileY(AnimationFrameSave frame, int valueAsInt)
        {
            if (frame == null)
            {
                throw new ArgumentNullException(nameof(frame));
            }
            TileMapInformation information = TileMapInformation;

            if (information != null && mTexture != null)
            {
                int pixelPosition = valueAsInt * information.TileHeight;
                frame.TopCoordinate    = pixelPosition / (float)mTexture.Height;
                frame.BottomCoordinate = frame.TopCoordinate + (information.TileHeight / (float)mTexture.Height);
            }
        }
Example #13
0
        private static void UpdateRectangleSelectorToFrame(AnimationFrameSave frame, Texture2D texture, RectangleSelector rectangleSelector)
        {
            rectangleSelector.Visible = texture != null;

            if (texture != null)
            {
                float leftPixel   = frame.LeftCoordinate * texture.Width;
                float rightPixel  = frame.RightCoordinate * texture.Width;
                float topPixel    = frame.TopCoordinate * texture.Height;
                float bottomPixel = frame.BottomCoordinate * texture.Height;

                rectangleSelector.Left   = leftPixel;
                rectangleSelector.Top    = topPixel;
                rectangleSelector.Width  = rightPixel - leftPixel;
                rectangleSelector.Height = bottomPixel - topPixel;
            }
        }
Example #14
0
        private Microsoft.Xna.Framework.Rectangle?GetSourceRetangleForFrame(AnimationFrameSave afs, Microsoft.Xna.Framework.Graphics.Texture2D texture2D)
        {
            if (afs == null || texture2D == null)
            {
                return(null);
            }
            else
            {
                Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle();
                rectangle.X     = Math.MathFunctions.RoundToInt(afs.LeftCoordinate * texture2D.Width);
                rectangle.Width = Math.MathFunctions.RoundToInt(afs.RightCoordinate * texture2D.Width) - rectangle.X;

                rectangle.Y      = Math.MathFunctions.RoundToInt(afs.TopCoordinate * texture2D.Height);
                rectangle.Height = Math.MathFunctions.RoundToInt(afs.BottomCoordinate * texture2D.Height) - rectangle.Y;

                return(rectangle);
            }
        }
Example #15
0
        public void AddFrameClick(object sender, EventArgs args)
        {
            AnimationChainSave chain = SelectedState.Self.SelectedChain;


            if (string.IsNullOrEmpty(ProjectManager.Self.FileName))
            {
                MessageBox.Show("You must first save this file before adding frames");
            }
            else if (chain == null)
            {
                MessageBox.Show("First select an Animation to add a frame to");
            }
            else
            {
                AnimationFrameSave afs = new AnimationFrameSave();

                if (chain.Frames.Count != 0)
                {
                    AnimationFrameSave copyFrom = chain.Frames[0];

                    afs.TextureName      = copyFrom.TextureName;
                    afs.FrameLength      = copyFrom.FrameLength;
                    afs.LeftCoordinate   = copyFrom.LeftCoordinate;
                    afs.RightCoordinate  = copyFrom.RightCoordinate;
                    afs.TopCoordinate    = copyFrom.TopCoordinate;
                    afs.BottomCoordinate = copyFrom.BottomCoordinate;
                }
                else
                {
                    afs.FrameLength = .1f; // default to .1 seconds.
                }

                chain.Frames.Add(afs);

                TreeViewManager.Self.RefreshTreeNode(chain);

                SelectedState.Self.SelectedFrame = afs;

                CallAnimationChainsChange();
            }
        }
Example #16
0
        private void UpdateSpriteToAnimationFrame(AnimationFrameSave afs, RenderingLibrary.Graphics.Sprite sprite)
        {
            sprite.Animate = false;

            sprite.Texture = WireframeManager.Self.GetTextureForFrame(afs);
            if (sprite.Texture != null)
            {
                sprite.SourceRectangle = GetSourceRetangleForFrame(afs, sprite.Texture);
                if (sprite.SourceRectangle.HasValue)
                {
                    sprite.Width  = sprite.SourceRectangle.Value.Width;
                    sprite.Height = sprite.SourceRectangle.Value.Height;
                }
            }
            sprite.FlipHorizontal = afs.FlipHorizontal;
            sprite.FlipVertical   = afs.FlipVertical;
            sprite.Animation      = mSprite.Animation;

            MoveSpriteAccordingToAlignmentAndOffset(sprite, afs);
        }
Example #17
0
        private void UpdateToSelectedFrame()
        {
            AnimationFrameSave frame = SelectedState.Self.SelectedFrame;

            Texture2D texture       = GetTextureForFrame(frame);
            Texture2D textureBefore = Texture;

            Texture = texture;


            if (texture != null)
            {
                mControl.DesiredSelectorCount = 1;
                foreach (var selector in mControl.RectangleSelectors)
                {
                    // We'll do it ourselves, to consider hotkeys
                    selector.AutoSetsCursor = false;
                }

                var rectangleSelector = mControl.RectangleSelector;
                UpdateRectangleSelectorToFrame(frame, texture, rectangleSelector);

                ShowSpriteOutlineForTexture(texture);

                this.WireframeEditControlsViewModel.SelectedTextureFilePath = GetTextureFileNameForFrame(frame).Standardized;
            }
            else
            {
                mControl.DesiredSelectorCount = 0;
            }

            UpdateLineGridToTexture(texture);


            this.mControl.RoundRectangleSelectorToUnit = PropertyGridManager.Self.UnitType == UnitType.Pixel;

            if (Texture != textureBefore)
            {
                ApplicationEvents.Self.CallWireframeTextureChange();
            }
        }
Example #18
0
        private void HandleDroppedImageOnAnimationChain(TreeNode targetNode, string folder, string fileNameCopy, bool isCtrlDown)
        {
            AnimationChainSave animationChainSave = targetNode.Tag as AnimationChainSave;
            string             relativeFile       = FileManager.MakeRelative(fileNameCopy, folder);

            bool madeChanges = false;

            if (isCtrlDown)
            {
                // ctrl is down, so add a new animation frame
                AnimationFrameSave newFrame = new AnimationFrameSave();
                newFrame.FrameLength = .1f;
                newFrame.TextureName = relativeFile;
                animationChainSave.Frames.Add(newFrame);

                madeChanges = true;
            }
            else
            {
                string message = "Set all contained AnimationFrames' texture?  Texture name:\n" + fileNameCopy;

                DialogResult result = MessageBox.Show(message, "Set all Textures?", MessageBoxButtons.OKCancel);

                if (result == DialogResult.OK)
                {
                    foreach (AnimationFrameSave animationFrame in animationChainSave.Frames)
                    {
                        animationFrame.TextureName = relativeFile;
                    }
                    madeChanges = true;
                }
            }

            if (madeChanges)
            {
                PreviewManager.Self.RefreshAll();
                WireframeManager.Self.RefreshAll();
                TreeViewManager.Self.RefreshTreeView();
                CallAnimationChainsChange();
            }
        }
Example #19
0
        public FilePath GetTextureFileNameForFrame(AnimationFrameSave frame)
        {
            FilePath returnValue = null;

            if (ProjectManager.Self.AnimationChainListSave != null)
            {
                string achxFolder = FlatRedBall.IO.FileManager.GetDirectory(ProjectManager.Self.FileName);

                if (frame != null && !string.IsNullOrEmpty(frame.TextureName))
                {
                    string fileName = achxFolder + frame.TextureName;

                    returnValue = fileName;
                }
                else
                {
                    returnValue = null;
                }
            }
            return(returnValue);
        }
Example #20
0
        private void CreateNewFrameFromMagicWand(int minX, int minY, int maxX, int maxY)
        {
            AnimationChainSave chain = SelectedState.Self.SelectedChain;


            if (string.IsNullOrEmpty(ProjectManager.Self.FileName))
            {
                MessageBox.Show("You must first save this file before adding frames");
            }
            else if (chain == null)
            {
                MessageBox.Show("First select an Animation to add a frame to");
            }
            else
            {
                AnimationFrameSave afs = new AnimationFrameSave();

                var texture    = this.mInspectableTexture.Texture;
                var achxFolder = FlatRedBall.IO.FileManager.GetDirectory(ProjectManager.Self.FileName);
                var relative   = FlatRedBall.IO.FileManager.MakeRelative(texture.Name, achxFolder);

                afs.TextureName = relative;

                afs.LeftCoordinate   = minX / (float)texture.Width;
                afs.RightCoordinate  = maxX / (float)texture.Width;
                afs.TopCoordinate    = minY / (float)texture.Height;
                afs.BottomCoordinate = maxY / (float)texture.Height;

                afs.FrameLength = .1f; // default to .1 seconds.

                chain.Frames.Add(afs);

                TreeViewManager.Self.RefreshTreeNode(chain);

                SelectedState.Self.SelectedFrame = afs;

                AnimationChainChange?.Invoke(this, null);
            }
        }
Example #21
0
        internal void HandlePaste()
        {
            var dataObject = Clipboard.GetDataObject();

            if (ProjectManager.Self.AnimationChainListSave != null)
            {
                if (dataObject.GetDataPresent("frame") && SelectedState.Self.SelectedChain != null)
                {
                    // paste this in the chain
                    // clone it, in case multiple pastes occur:
                    AnimationFrameSave whatToCopy = dataObject.GetData("frame") as AnimationFrameSave;
                    AnimationFrameSave newAfs     = FileManager.CloneObject(whatToCopy);
                    SelectedState.Self.SelectedChain.Frames.Add(newAfs);
                    TreeViewManager.Self.RefreshTreeNode(SelectedState.Self.SelectedChain);
                    SelectedState.Self.SelectedFrame = newAfs;
                    MainControl.Self.RaiseAnimationChainChanges(null, null);
                }
                else if (dataObject.GetDataPresent("chain"))
                {
                    object             data       = dataObject.GetData("chain");
                    AnimationChainSave whatToCopy = data as AnimationChainSave;
                    AnimationChainSave newAcs     = FileManager.CloneObject(whatToCopy);

                    List <string> existingNames = ProjectManager.Self.AnimationChainListSave.AnimationChains.Select(item => item.Name).ToList();

                    newAcs.Name = StringFunctions.MakeStringUnique(newAcs.Name, existingNames, 2);


                    ProjectManager.Self.AnimationChainListSave.AnimationChains.Add(newAcs);
                    TreeViewManager.Self.RefreshTreeNode(newAcs);

                    MainControl.Self.RaiseAnimationChainChanges(null, null);

                    SelectedState.Self.SelectedChain = newAcs;
                }
            }
        }
Example #22
0
        private void UpdateToSelectedAnimation(bool skipPushed = false)
        {
            if (mControl.RectangleSelector != null)
            {
                mControl.RectangleSelector.Visible = false;
            }

            AnimationFrameSave afs = null;

            afs = SelectedState.Self.SelectedChain.Frames[0];
            if (afs.TextureName != null)
            {
                Texture2D texture = GetTextureForFrame(afs);
                Texture = texture;

                ShowSpriteOutlineForTexture(texture);
                UpdateLineGridToTexture(texture);


                bool anyDiffer = SelectedState.Self.SelectedChain.Frames.Any(item => item.TextureName != afs.TextureName);

                if (!anyDiffer)
                {
                    UpdateSelectorsToAnimation(skipPushed, texture);
                }
                else
                {
                    mControl.DesiredSelectorCount = 0;
                }
            }

            // Do we need to check if it's changed?
            //if (Texture != textureBefore)
            {
                ApplicationEvents.Self.CallWireframeTextureChange();
            }
        }
Example #23
0
        private void UpdateOnionSkinSprites()
        {
            bool shouldShow = SelectedState.Self.SelectedFrame != null &&
                              SelectedState.Self.SelectedChain.Frames.Count > 1 &&
                              mPreviewControls.IsOnionSkinVisible;

            if (shouldShow)
            {
                if (mOnionSkinSprites.Count == 0)
                {
                    RenderingLibrary.Graphics.Sprite sprite = new RenderingLibrary.Graphics.Sprite(null);
                    sprite.Color = new Microsoft.Xna.Framework.Color(1, 1, 1, .5f);
                    sprite.Z     = -1;
                    mManagers.SpriteManager.Add(sprite);
                    mOnionSkinSprites.Add(sprite);
                }

                int indexToShow = SelectedState.Self.SelectedChain.Frames.IndexOf(SelectedState.Self.SelectedFrame) - 1;
                if (indexToShow == -1)
                {
                    indexToShow = SelectedState.Self.SelectedChain.Frames.Count - 1;
                }

                AnimationFrameSave frame = SelectedState.Self.SelectedChain.Frames[indexToShow];

                UpdateSpriteToAnimationFrame(frame, mOnionSkinSprites[0]);
            }
            else
            {
                while (mOnionSkinSprites.Count != 0)
                {
                    RenderingLibrary.Graphics.Sprite sprite = mOnionSkinSprites[0];
                    mManagers.SpriteManager.Remove(sprite);
                    mOnionSkinSprites.RemoveAt(0);
                }
            }
        }
Example #24
0
        private void UpdateToSelectedFrame()
        {
            AnimationFrameSave frame = SelectedState.Self.SelectedFrame;

            Texture2D texture       = GetTextureForFrame(frame);
            Texture2D textureBefore = Texture;

            Texture = texture;


            mControl.DesiredSelectorCount = 1;
            if (texture != null)
            {
                var rectangleSelector = mControl.RectangleSelector;

                mControl.DesiredSelectorCount = 1;

                UpdateRectangleSelectorToFrame(frame, texture, rectangleSelector);

                ShowSpriteOutlineForTexture(texture);
            }
            else
            {
                mControl.RectangleSelector.Visible = false;
            }

            UpdateLineGridToTexture(texture);



            this.mControl.RoundRectangleSelectorToUnit = PropertyGridManager.Self.UnitType == UnitType.Pixel;

            if (Texture != textureBefore)
            {
                ApplicationEvents.Self.CallWireframeTextureChange();
            }
        }
Example #25
0
        private void MoveSpriteAccordingToAlignmentAndOffset(RenderingLibrary.Graphics.Sprite sprite, AnimationFrameSave frame)
        {
            // Event though we may not be rendering the main Sprite, we want to use the main Sprite's animation:
            IAnimation animation = mSprite.Animation;

            if (sprite != null && sprite.Visible && mSprite.Animation != null)
            {
                int index = sprite.Animation.CurrentFrameIndex;

                float animationXOffset = 0;
                float animationYOffset = 0;

                AnimationChainSave chain = SelectedState.Self.SelectedChain;



                if (chain != null && chain.Frames.Count > index)
                {
                    if (frame == null)
                    {
                        frame = chain.Frames[index];
                    }

                    animationXOffset = frame.RelativeX * OffsetMultiplier;
                    animationYOffset = frame.RelativeY * OffsetMultiplier;
                }

                if (SpriteAlignment == Data.SpriteAlignment.Center)
                {
                    float xOffset = (-sprite.EffectiveWidth) / 2.0f;
                    float yOffset = (-sprite.EffectiveHeight) / 2.0f;

                    sprite.X = xOffset + animationXOffset;
                    sprite.Y = yOffset - animationYOffset;
                }
                else
                {
                    sprite.X = 0 + animationXOffset;
                    sprite.Y = 0 - animationYOffset;
                }
            }
        }
Example #26
0
        public Texture2D GetTextureForFrame(AnimationFrameSave frame)
        {
            var fileName = GetTextureFileNameForFrame(frame);

            return(GetTextureFromFile(fileName));
        }
Example #27
0
        void CoordinateChange(object sender, MemberChangeArgs args)
        {
            AnimationFrameSave frame = Instance as AnimationFrameSave;

            if (mTexture == null)
            {
                // We can't do anything.
            }
            else
            {
                if (args.Member == "X")
                {
                    int oldValue = MathFunctions.RoundToInt(frame.LeftCoordinate * mTexture.Width);
                    int newValue = ((int)args.Value);

                    int   increaseAsInt          = newValue - oldValue;
                    float increaseAsTextureCoord = increaseAsInt / (float)mTexture.Width;

                    // Users expect the entire frame to shift, so we want to shift the right coordinates too.
                    frame.LeftCoordinate  += increaseAsTextureCoord;
                    frame.RightCoordinate += increaseAsTextureCoord;

                    SetForPixelCoordinates(ref frame.LeftCoordinate, mTexture.Width);
                    SetForPixelCoordinates(ref frame.RightCoordinate, mTexture.Width);
                }
                else if (args.Member == "Y")
                {
                    int oldValue = MathFunctions.RoundToInt(frame.TopCoordinate * mTexture.Height);
                    int newValue = ((int)args.Value);

                    int   increaseAsInt          = newValue - oldValue;
                    float increaseAsTextureCoord = increaseAsInt / (float)mTexture.Height;



                    frame.TopCoordinate    += increaseAsTextureCoord;
                    frame.BottomCoordinate += increaseAsTextureCoord;

                    SetForPixelCoordinates(ref frame.TopCoordinate, mTexture.Height);
                    SetForPixelCoordinates(ref frame.BottomCoordinate, mTexture.Height);
                }
                else if (args.Member == "Width")
                {
                    float widthInCoords = ((int)args.Value) / (float)mTexture.Width;
                    frame.RightCoordinate = frame.LeftCoordinate + widthInCoords;
                }
                else if (args.Member == "Height")
                {
                    float heightInCoords = ((int)args.Value) / (float)mTexture.Height;
                    frame.BottomCoordinate = frame.TopCoordinate + heightInCoords;
                }
                else if (args.Member == "TileX")
                {
                    int valueAsInt = (int)args.Value;
                    SetTileX(frame, valueAsInt);
                }
                else if (args.Member == "TileY")
                {
                    int valueAsInt = (int)args.Value;
                    SetTileY(frame, valueAsInt);
                }
            }
        }