// Initialize necessary variables GraphicsDevice graphicsDevice = graphics.GraphicsDevice; SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice); Rectangle rect = new Rectangle(200, 150, 100, 50); // Begin sprite drawing process spriteBatch.Begin(); // Draw an orange rectangle using the Rectangle class and a SolidBrush spriteBatch.DrawRectangle(rect, Color.Orange); // End sprite drawing process spriteBatch.End();
// Initialize necessary variables GraphicsDevice graphicsDevice = graphics.GraphicsDevice; SpriteBatch spriteBatch = new SpriteBatch(graphicsDevice); Texture2D texture = Content.LoadIn this example, we load a texture and set its rotation and scale properties using the MathHelper and Vector2 classes. We then use the SpriteBatch.Draw() method to draw the texture onto the screen with the specified rotation and scaling factors. Finally, we end the sprite drawing process using the SpriteBatch.End() method. Package Library: Microsoft.Xna.Framework.Graphics("exampleTexture"); Vector2 position = new Vector2(200, 150); // Begin sprite drawing process spriteBatch.Begin(); // Set the sprite rotation and scale float rotation = MathHelper.ToRadians(45f); Vector2 origin = new Vector2(texture.Width / 2, texture.Height / 2); Vector2 scale = new Vector2(0.75f); // Draw the sprite with rotation and scaling spriteBatch.Draw(texture, position, null, Color.White, rotation, origin, scale, SpriteEffects.None, 0f); // End sprite drawing process spriteBatch.End();