Exemplo n.º 1
0
        public FrameSet(AtlasAnimation animTexture, string trackName)
        {
            Texture      = animTexture.Texture;
            SourceRegion = animTexture.SourceRegion;

            if (!animTexture.TryGetTrack(trackName, out List <AtlasAnimationFrame> frames))
            {
                ClippingRegion = Raccoon.Rectangle.Empty;
                return;
            }

            _frames = new Frame[frames.Count];

            for (int i = 0; i < frames.Count; i++)
            {
                AtlasAnimationFrame atlasAnimationFrame = frames[i];

                _frames[i] = new Frame {
                    ClippingRegion = atlasAnimationFrame.ClippingRegion,
                    Destination    = atlasAnimationFrame.OriginalFrame,
                };
            }


            if (_frames.Length > 0)
            {
                Columns           = _frames.Length;
                Rows              = 1;
                FrameSize         = _frames[0].Destination.Size;
                CurrentFrameIndex = 0;
            }
        }
Exemplo n.º 2
0
        public void Prepare(Rectangle centerSlice, AtlasAnimation atlasAnimation, int frameIndex) {
            if (atlasAnimation == null) {
                throw new System.ArgumentNullException(nameof(atlasAnimation));
            }

            if (!atlasAnimation.TryGetDefaultTrack(out List<AtlasAnimationFrame> frames)) {
                throw new System.ArgumentException("Supplied atlas animation doesn't contains default track.");
            }

            if (frames.Count <= 0) {
                throw new System.InvalidOperationException("There is no frames at default track.");
            } else if (frameIndex < 0 || frameIndex >= frames.Count) {
                throw new System.IndexOutOfRangeException($"Supplied frame index '{frameIndex}' is out of valid frames range [0, {frames.Count - 1}] at default track.");
            }

            Texture = atlasAnimation.Texture;
            AtlasAnimationFrame frame = frames[frameIndex];

            bool wasUsingCustomSize = _isUsingCustomSize;
            Size previousSize = Size;
            _isUsingCustomSize = false;

            Prepare(
                centerSlice,
                atlasAnimation.SourceRegion,
                frame.ClippingRegion,
                frame.OriginalFrame
            );

            Load();
            _baseSize = Size;

            if (wasUsingCustomSize) {
                Setup(previousSize);
            }
        }