Example #1
0
        private void LoadAnimationIntoCache(string modelKey)
        {
            // Builds the animation object for all model, action, direction
            // combinations. Object is then added to the AnimationCache.
            AnimationCache animationCache = AnimationCache.Instance;

            foreach (BaseAction directionalAction in _directionalActions)
            {
                // Use the respective importer for the action
                IAnimationImporter animationImporter = directionalAction.GetAnimationImporter();
                var newAnimations = animationImporter.ImportAnimations(modelKey, DirectionType.Down);
                foreach (AnimationDNABlock newAnimation in newAnimations)
                {
                    string animationKey =
                        $"{modelKey}_{directionalAction.AnimationTag}_{DirectionType.GetAnimationForDirection(newAnimation.Direction)}";
                    animationCache.Add(animationKey, newAnimation);
                }
            }

            // The "Idle" action reuses the first image of the death animation, so we need
            // to import the first frame of all death sprites without a direction tag.
            BaseAction deathAnimation  = new DeathAction();
            var        deathImporter   = deathAnimation.GetAnimationImporter();
            var        deathAnimations = deathImporter.ImportAnimations(modelKey, DirectionType.None);

            foreach (AnimationDNABlock newAnimation in deathAnimations)
            {
                string animationKey = $"{modelKey}_{deathAnimation.AnimationTag}";
                animationCache.Add(animationKey, newAnimation);
            }
        }
Example #2
0
        private static AnimationDNABlock GetAnimation(string modelKey, BaseAction actionAnimation, string direction)
        {
            // Fetches an animation from the animation store/cache
            AnimationCache animationCache = AnimationCache.Instance;
            string         animationKey   = modelKey;

            animationKey = direction.Equals(DirectionType.None)
                ? $"{animationKey}_{actionAnimation.AnimationTag}"
                : $"{animationKey}_{actionAnimation.AnimationTag}_{DirectionType.GetAnimationForDirection(direction)}";
            return(animationCache.Get(animationKey));
        }