createRegion() public method

public createRegion ( string name, int x, int y, int width, int height, float pivotX = 0.5f, float pivotY = 0.5f ) : Subtexture
name string
x int
y int
width int
height int
pivotX float
pivotY float
return Nez.Textures.Subtexture
        public static TexturePackerAtlas create(Texture2D texture, int regionWidth, int regionHeight, int maxRegionCount = int.MaxValue, int margin = 0, int spacing = 0)
        {
            var textureAtlas = new TexturePackerAtlas(texture);
            var count        = 0;
            var width        = texture.Width - margin;
            var height       = texture.Height - margin;
            var xIncrement   = regionWidth + spacing;
            var yIncrement   = regionHeight + spacing;

            for (var y = margin; y < height; y += yIncrement)
            {
                for (var x = margin; x < width; x += xIncrement)
                {
                    var regionName = string.Format("{0}{1}", texture.Name ?? "region", count);
                    textureAtlas.createRegion(regionName, x, y, regionWidth, regionHeight);
                    count++;

                    if (count >= maxRegionCount)
                    {
                        return(textureAtlas);
                    }
                }
            }

            return(textureAtlas);
        }
Ejemplo n.º 2
0
        public static TexturePackerAtlas create( Texture2D texture, int regionWidth, int regionHeight, int maxRegionCount = int.MaxValue, int margin = 0, int spacing = 0 )
        {
            var textureAtlas = new TexturePackerAtlas( texture );
            var count = 0;
            var width = texture.Width - margin;
            var height = texture.Height - margin;
            var xIncrement = regionWidth + spacing;
            var yIncrement = regionHeight + spacing;

            for( var y = margin; y < height; y += yIncrement )
            {
                for( var x = margin; x < width; x += xIncrement )
                {
                    var regionName = string.Format( "{0}{1}", texture.Name ?? "region", count );
                    textureAtlas.createRegion( regionName, x, y, regionWidth, regionHeight );
                    count++;

                    if( count >= maxRegionCount )
                        return textureAtlas;
                }
            }

            return textureAtlas;
        }