예제 #1
0
        void GenerateRects(int cellWidth, int cellHeight, int totalFrames, int padding, int cellOffset = 0)
        {
            _atlasData.Clear();
            _hasSlicedContent = true;

            var cols = _textureSize.X / cellWidth;
            var rows = _textureSize.Y / cellHeight;
            var i    = 0;

            for (var y = 0; y < rows; y++)
            {
                for (var x = 0; x < cols; x++)
                {
                    // skip everything before the first cellOffset
                    if (i++ < cellOffset)
                    {
                        continue;
                    }

                    var padX = padding * x;
                    var padY = padding * y;
                    _atlasData.SourceRects.Add(new Rectangle(x * cellWidth + padX, y * cellHeight + padY, cellWidth, cellHeight));
                    _atlasData.Names.Add($"F{i}");
                    _atlasData.Origins.Add(Vector2Ext.HalfVector());

                    // once we hit the max number of cells to include bail out. were done.
                    if (_atlasData.SourceRects.Count == totalFrames)
                    {
                        return;
                    }
                }
            }
        }