Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of <see cref="SpriteFromSheet"/> with the specified <see cref="SpriteSheet"/>.
        /// <see cref="CurrentFrame"/> is initialized according to the specified <paramref name="spriteName"/>.
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="spriteName">The name of the sprite.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">sheet</exception>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException">No sprite in the sheet has the given name.</exception>
        /// <remarks>If two sprites have the provided name then the first sprite found is used.</remarks>
        public static SpriteFromSheet Create(SpriteSheet sheet, string spriteName)
        {
            if (sheet == null) throw new ArgumentNullException(nameof(sheet));

            return new SpriteFromSheet
            {
                Sheet = sheet,
                CurrentFrame = sheet.FindImageIndex(spriteName)
            };
        }
Ejemplo n.º 2
0
 private Entity CreateSpriteEntity(SpriteSheet sheet, string frameName)
 {
     return new Entity(frameName)
     {
         new SpriteComponent
         {
             SpriteProvider = new SpriteFromSheet { Sheet = sheet },
             CurrentFrame = sheet.FindImageIndex(frameName)
         }
     };
 }
Ejemplo n.º 3
0
        private Entity CreateSpriteEntity(SpriteSheet sheet, string frameName, bool addToScene = true)
        {
            var entity = new Entity(frameName)
            {
                new SpriteComponent
                {
                    SpriteProvider = new SpriteFromSheet { Sheet = sheet },
                    CurrentFrame = sheet.FindImageIndex(frameName)
                }
            };

            if (addToScene)
                entities.Add(entity);

            return entity;
        }