Example #1
0
        /// <summary>
        ///     This caches a sprite for easier look up and duplicate detection.
        ///     Each sprite is cached as a string.
        /// </summary>
        /// <param name="index">
        ///     Index where the sprite's cached value should be stored in the
        ///     <see cref="cache" /> array.
        /// </param>
        /// <param name="data">
        ///     An array of ints that represents the sprite's color data.
        /// </param>
        private void CacheSprite(int index, int[] data)
        {
            cache[index] = SpriteChipUtil.SpriteDataToString(data);

            var totalPixels = width * height;

            var tmpPixels = new int[totalPixels];

            Array.Copy(data, tmpPixels, totalPixels);
            pixelDataCache[index] = tmpPixels;
        }
Example #2
0
        /// <summary>
        ///     Finds a sprite by looking it up against the cache. Returns -1 if no
        ///     sprite is found. This is used for insuring duplicate sprites aren't
        ///     added to the TextureData.
        /// </summary>
        /// <param name="pixels">
        ///     An array of ints representing the sprite's color data.
        /// </param>
        /// <returns>
        /// </returns>
        public int FindSprite(int[] pixels, bool emptyCheck = false)
        {
            if (emptyCheck)
            {
                if (IsEmpty(pixels))
                {
                    return(-1);
                }
            }

            var sprite = SpriteChipUtil.SpriteDataToString(pixels);

            return(Array.IndexOf(cache, sprite));
        }