Nez.Portable/Graphics/Textures/Subtexture.cs
/// <summary>
/// provides a List of subtextures given an atlas with equally spaced rows/columns of sprites
/// </summary>
/// <returns>The from atlas.</returns>
/// <param name="texture">Texture.</param>
/// <param name="cellWidth">Cell width.</param>
/// <param name="cellHeight">Cell height.</param>
/// <param name="cellOffset">the first cell to include while processing. 0 based indexing.</param>
/// <param name="maxCellsToInclude">Max cells to included.</param>
provides a List of subtextures given an atlas with equally spaced rows/columns of sprites
provides a List of subtextures given an atlas with equally spaced rows / columns of sprites
public static List<Subtexture> subtexturesFromAtlas(
            Texture2D texture,
            int cellWidth,
            int cellHeight,
            int cellOffset = 0,
            int maxCellsToInclude = int.MaxValue)
        {
            var subtextures = new List<Subtexture>();
            var cols = texture.Width / cellWidth;
            var rows = texture.Height / cellHeight;
            var i = 0;
            for (var y = 0; y < rows; y++)
            {
                for (var x = 0; x < cols; x++)
                {
                    if (i++ < cellOffset)
                        continue;
                    subtextures.Add(
                        new Subtexture(texture, new Rectangle(x * cellWidth, y * cellHeight, cellWidth, cellHeight)));
                    if (subtextures.Count == maxCellsToInclude)
                        break;
                }
            }
            return subtextures;
        }
public static List < Subtexture > subtexturesFromAtlas ( Texture2D texture , int cellWidth , int cellHeight , int cellOffset = 0 , int maxCellsToInclude = int . MaxValue ) { var subtextures = new List < Subtexture > ( ) ; var cols = texture . Width / cellWidth ; var rows = texture . Height / cellHeight ; var i = 0 ; for ( var y = 0 ; y < rows ; y ++ ) { for ( var x = 0 ; x < cols ; x ++ ) { if ( i ++ < cellOffset ) continue ; subtextures . Add ( new Subtexture ( texture , new Rectangle ( x * cellWidth , y * cellHeight , cellWidth , cellHeight ) ) ) ; if ( subtextures . Count == maxCellsToInclude ) break ; } } return subtextures ; }
provides a List of subtextures given an atlas with equally spaced rows/columns of sprites
provides a List of subtextures given an atlas with equally spaced rows / columns of sprites
// skip everything before the first cellOffset // once we hit the max number of cells to include bail out. were done.
The from atlas.
The from atlas .
texture
Texture2D
None
cellWidth
int
None
cellHeight
int
None
cellOffset
int
the first cell to include while processing. 0 based indexing.
the first cell to include while processing . 0 based indexing .
maxCellsToInclude
int
Max cells to included.
Max cells to included .