/// <summary>
        /// Function to generate animations for the entities in the application.
        /// </summary>
        private void GenerateAnimations()
        {
            var builder = new GorgonAnimationBuilder();

            IGorgonAnimation planetRotation = builder
                                              .Clear()
                                              .EditRotation()
                                              .SetKey(new GorgonKeyVector3(0, new DX.Vector3(0, 0, 180)))
                                              .SetKey(new GorgonKeyVector3(600, new DX.Vector3(0, 360, 180)))
                                              .EndEdit()
                                              .RotationInterpolationMode(TrackInterpolationMode.Linear)
                                              .Build("PlanetRotation");

            planetRotation.IsLooped          = true;
            _animations[planetRotation.Name] = planetRotation;

            IGorgonAnimation cloudRotation = builder
                                             .Clear()
                                             .EditRotation()
                                             .SetKey(new GorgonKeyVector3(0, new DX.Vector3(0, 0, 180)))
                                             .SetKey(new GorgonKeyVector3(600, new DX.Vector3(100, 180, 180)))
                                             .SetKey(new GorgonKeyVector3(1200, new DX.Vector3(0, 360, 180)))
                                             .EndEdit()
                                             .RotationInterpolationMode(TrackInterpolationMode.Linear)
                                             .Build("CloudRotation");

            cloudRotation.IsLooped          = true;
            _animations[cloudRotation.Name] = cloudRotation;

            GorgonSprite[] frames = Sprites.Where(item => item.Key.StartsWith("Fighter_Engine_F", StringComparison.OrdinalIgnoreCase))
                                    .OrderBy(item => item.Key)
                                    .Select(item => item.Value)
                                    .ToArray();

            IGorgonAnimation engineGlow = builder
                                          .Clear()
                                          .Edit2DTexture()
                                          .SetKey(new GorgonKeyTexture2D(0, frames[0].Texture, frames[0].TextureRegion, frames[0].TextureArrayIndex))
                                          .SetKey(new GorgonKeyTexture2D(0.1f, frames[1].Texture, frames[1].TextureRegion, frames[1].TextureArrayIndex))
                                          .SetKey(new GorgonKeyTexture2D(0.2f, frames[2].Texture, frames[2].TextureRegion, frames[2].TextureArrayIndex))
                                          .SetKey(new GorgonKeyTexture2D(0.3f, frames[1].Texture, frames[1].TextureRegion, frames[1].TextureArrayIndex))
                                          .EndEdit()
                                          .RotationInterpolationMode(TrackInterpolationMode.Linear)
                                          .Build("EngineGlow");

            engineGlow.IsLooped          = true;
            _animations[engineGlow.Name] = engineGlow;
        }
Beispiel #2
0
        /// <summary>
        /// Function to build the animations.
        /// </summary>
        /// <param name="sprites">The list of sprites loaded from the file system.</param>
        private static void BuildAnimations(IReadOnlyDictionary <string, GorgonSprite> sprites)
        {
            var animBuilder = new GorgonAnimationBuilder();

            // Extract the sprites that have the animation frames.
            // We'll use the name of the sprite to determine the type of animation and ordering.
            // If we had an animation editor in the editor application, this would be a lot easier, but for now we'll have to do this.
            // If I create an editor, I'll try to replace this code with the animations in the editor file system.
            GorgonSprite[] upFrames = sprites.OrderBy(item => item.Key)
                                      .Where(item => item.Key.StartsWith("Guy_Up_", StringComparison.OrdinalIgnoreCase))
                                      .Select(item => item.Value)
                                      .ToArray();

            IEnumerable <GorgonSprite> turnFrames = sprites.OrderBy(item => item.Key)
                                                    .Where(item => item.Key.StartsWith("Guy_Turn_", StringComparison.OrdinalIgnoreCase))
                                                    .Select(item => item.Value);

            GorgonSprite[] walkLeftFrames = sprites.OrderBy(item => item.Key)
                                            .Where(item => item.Key.StartsWith("Guy_Left_", StringComparison.OrdinalIgnoreCase))
                                            .Select(item => item.Value)
                                            .ToArray();

            float time = 0;

            // Build animation for walking up.
            for (int i = 0; i < upFrames.Length; ++i)
            {
                GorgonSprite sprite = upFrames[i];

                animBuilder.Edit2DTexture()
                .SetKey(new GorgonKeyTexture2D(time, sprite.Texture, sprite.TextureRegion, 0))
                .EndEdit();

                time += 0.15f;
            }

            // Reverse the animation so we don't get popping as it loops.
            for (int i = upFrames.Length - 2; i >= 1; --i)
            {
                GorgonSprite sprite = upFrames[i];

                animBuilder.Edit2DTexture()
                .SetKey(new GorgonKeyTexture2D(time, sprite.Texture, sprite.TextureRegion, 0))
                .EndEdit();

                time += 0.15f;
            }

            _animations[AnimationName.WalkUp]          = animBuilder.Build("Walk Up");
            _animations[AnimationName.WalkUp].IsLooped = true;


            // Build animation for turning left.
            time = 0;
            animBuilder.Clear();
            foreach (GorgonSprite sprite in turnFrames)
            {
                animBuilder.Edit2DTexture()
                .SetKey(new GorgonKeyTexture2D(time, sprite.Texture, sprite.TextureRegion, 0))
                .EndEdit();

                time += 0.20f;
            }
            _animations[AnimationName.Turn] = animBuilder.Build("Turn Left");

            // Build animation for walking left.
            time = 0;
            animBuilder.Clear();
            for (int i = 0; i < walkLeftFrames.Length; ++i)
            {
                GorgonSprite sprite = walkLeftFrames[i];
                animBuilder.Edit2DTexture()
                .SetKey(new GorgonKeyTexture2D(time, sprite.Texture, sprite.TextureRegion, 0))
                .EndEdit();

                time += 0.15f;
            }

            _animations[AnimationName.WalkLeft]          = animBuilder.Build("Walk Left");
            _animations[AnimationName.WalkLeft].IsLooped = true;

            // Finally, we'll need a controller to play and update the animations over time.
            _controller = new GorgonSpriteAnimationController();
        }