コード例 #1
0
        public Animation(AtlasAnimation animTexture)
        {
            // TODO: support KeyType with AtlasAnimation, converting string animations label to KeyType enum
            if (typeof(KeyType) != typeof(string))
            {
                throw new System.NotSupportedException($"KeyType '{typeof(KeyType)}' doesn't support AtlasAnimationTexture, switch to string.");
            }

            Texture        = animTexture.Texture;
            SourceRegion   = animTexture.SourceRegion;
            ClippingRegion = animTexture["all"][0].ClippingRegion;

            foreach (KeyValuePair <string, List <AtlasAnimationFrame> > anim in animTexture)
            {
                Rectangle[] framesRegions     = new Rectangle[anim.Value.Count];
                int[]       durations         = new int[framesRegions.Length];
                Rectangle[] destinationFrames = new Rectangle[anim.Value.Count];

                int i = 0;
                foreach (AtlasAnimationFrame frame in anim.Value)
                {
                    framesRegions[i]     = frame.ClippingRegion;
                    durations[i]         = frame.Duration;
                    destinationFrames[i] = new Rectangle(frame.OriginalFrame.Position, frame.ClippingRegion.Size);
                    i++;
                }

                Add((KeyType)(object)anim.Key, framesRegions, destinationFrames, durations);
            }
        }
コード例 #2
0
ファイル: FrameSet.cs プロジェクト: lucas-miranda/Raccoon
        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;
            }
        }
コード例 #3
0
ファイル: Atlas.cs プロジェクト: lucas-miranda/Raccoon
        public bool TryRetrieveAnimation(string name, out AtlasAnimation atlasAnimation)
        {
            if (!TryRetrieveSubTexture(name, out AtlasSubTexture subTexture) || !(subTexture is AtlasAnimation animation))
            {
                atlasAnimation = null;
                return(false);
            }

            atlasAnimation = animation;
            return(true);
        }
コード例 #4
0
ファイル: NineSlice.cs プロジェクト: lucas-miranda/Raccoon
        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);
            }
        }
コード例 #5
0
ファイル: NineSlice.cs プロジェクト: lucas-miranda/Raccoon
 public NineSlice(Rectangle centerSlice, AtlasAnimation atlasAnimation, int frameIndex) : this() {
     Prepare(centerSlice, atlasAnimation, frameIndex);
 }
コード例 #6
0
ファイル: FrameSet.cs プロジェクト: lucas-miranda/Raccoon
 public FrameSet(AtlasAnimation animTexture) : this(animTexture, AtlasAnimation.DefaultAllFramesTrackName)
 {
 }