Microsoft.Xna.Framework.Graphics.SpriteBatcher.CreateBatchItem C# (CSharp) Method

CreateBatchItem() public method

Create an instance of SpriteBatchItem if there is none available in the free item queue. Otherwise, a previously allocated SpriteBatchItem is reused.
public CreateBatchItem ( ) : SpriteBatchItem
return SpriteBatchItem
        public SpriteBatchItem CreateBatchItem()
        {
            SpriteBatchItem item;
            if (_freeBatchItemQueue.Count > 0)
                item = _freeBatchItemQueue.Dequeue();
            else
                item = new SpriteBatchItem();
            _batchItemList.Add(item);
            return item;
        }

Usage Example

Example #1
0
        public void Draw(Texture2D texture, Vector2 position, Nullable <Rectangle> sourceRectangle, Color color, float rotation,
                         Vector2 origin, Vector2 scale, SpriteEffects effect, float depth)
        {
            if (texture == null)
            {
                throw new ArgumentException("texture");
            }

            SpriteBatchItem item = _batcher.CreateBatchItem();

            item.Depth     = depth;
            item.TextureID = (int)texture.ID;

            Rectangle rect;

            if (sourceRectangle.HasValue)
            {
                rect = sourceRectangle.Value;
            }
            else
            {
                rect = new Rectangle(0, 0, texture.Image.ImageWidth, texture.Image.ImageHeight);
            }

            Vector2 texCoordTL = texture.Image.GetTextureCoord(rect.X, rect.Y);
            Vector2 texCoordBR = texture.Image.GetTextureCoord(rect.X + rect.Width, rect.Y + rect.Height);

            if ((effect & SpriteEffects.FlipVertically) != 0)
            {
                float temp = texCoordBR.Y;
                texCoordBR.Y = texCoordTL.Y;
                texCoordTL.Y = temp;
            }
            if ((effect & SpriteEffects.FlipHorizontally) != 0)
            {
                float temp = texCoordBR.X;
                texCoordBR.X = texCoordTL.X;
                texCoordTL.X = temp;
            }

            item.Set
            (
                position.X,
                position.Y,
                -origin.X * scale.X,
                -origin.Y * scale.Y,
                rect.Width * scale.X,
                rect.Height * scale.Y,
                (float)Math.Sin(rotation),
                (float)Math.Cos(rotation),
                color,
                texCoordTL,
                texCoordBR
            );
        }
All Usage Examples Of Microsoft.Xna.Framework.Graphics.SpriteBatcher::CreateBatchItem