Texture2D sheetTexture = Content.Load<Texture2D>("characters/hero_sheet"); SpriteSheet heroSheet = new SpriteSheet(sheetTexture, 32, 32); heroSheet.AddRegion("idle", new Rectangle(0, 0, 32, 32)); heroSheet.AddRegion("walk1", new Rectangle(32, 0, 32, 32)); heroSheet.AddRegion("walk2", new Rectangle(64, 0, 32, 32));
Here's how to do it right. Create a dedicated class to manage your sheet: monogame sprite sheet
public void Update(GameTime gameTime)
Cache your Rectangle regions. The code above does this via Dictionary<string, Rectangle> . Texture2D sheetTexture = Content
_texture = texture; _regions = new Dictionary<string, Rectangle>(); int columns = texture.Width / frameWidth; int rows = texture.Height / frameHeight; // Auto-generate named regions: "0_0", "0_1", etc. for (int y = 0; y < rows; y++) for (int x = 0; x < columns; x++) string name = $"x_y"; Rectangle region = new Rectangle( x * frameWidth, y * frameHeight, frameWidth, frameHeight); _regions[name] = region; _texture = texture