Home › MonoGame › MonoGame AGENTS.md

MonoGame AGENTS.md

AGENTS.md for 2D/3D games in C# with MonoGame 3.8: game loop, content pipeline, scenes, and allocation-free updates.

AGENTS.mdMonoGame

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

AGENTS.mdDownload  
# AGENTS.md: MonoGame (C#)

## Commands
`dotnet build` · `dotnet run --project src/Game` · `dotnet test` · content: `dotnet mgcb-editor` (GUI) or build via the `Content.mgcb` file

## Structure
- `Game1` (rename to the game's name) only wires services and the scene manager. Each scene/screen is a class with `Load`, `Update(GameTime)`, `Draw(SpriteBatch)`, `Unload`.
- Game logic (rules, AI, physics math) in plain C# classes without MonoGame dependencies where possible, so they're unit-testable.
- Assets go through the content pipeline (`Content.mgcb`); load with `Content.Load<Texture2D>("sprites/player")` once in `LoadContent`/scene load, never in `Update` or `Draw`.

## Loop rules
- Use `(float)gameTime.ElapsedGameTime.TotalSeconds` for movement; consider a fixed timestep (`IsFixedTimeStep = true`) for physics.
- Input through a small input service that tracks previous and current `KeyboardState`/`GamePadState` for "pressed this frame" checks.
- One `SpriteBatch.Begin/End` per layer; sort and batch by texture (use texture atlases). Use `SamplerState.PointClamp` for pixel art.
- Avoid allocations in `Update`/`Draw`: no LINQ, no `new` per frame, reuse lists, pool bullets/particles, cache strings for HUD text.
- Resolution independence via a render target at the virtual resolution, scaled to the window.
- Dispose `RenderTarget2D` and other GPU resources you create.

## Done
Build has no warnings, tests pass, and the game runs and plays the changed feature.

More: all MonoGame rules · all AGENTS.md rules

Related rules

Bevy game engine AGENTS.md

AGENTS.md for Bevy (0.16+) games in Rust: ECS systems, plugins, required components, and fast dev builds.

AGENTS.mdBevy (Rust)

Defold game engine AGENTS.md

AGENTS.md for Defold games in Lua: game objects and components, message passing, script lifecycle, and native extensions.

AGENTS.mdDefold

GameMaker GML AGENTS.md

AGENTS.md for GameMaker (2024+ runtime) projects in GML: objects and events, structs and methods, and clean state.

AGENTS.mdGameMaker

Godot 4 GDScript AGENTS.md

AGENTS.md for Godot 4 projects using typed GDScript, signals and scene composition.

AGENTS.mdGodot

Pygame (pygame-ce) AGENTS.md

AGENTS.md for 2D games in Python with pygame-ce 2.5+: game loop, scenes, sprites, assets, and testable logic.

AGENTS.mdPygame

Phaser 3 browser game rules

Windsurf rules for 2D browser games with Phaser 3, TypeScript and Vite.

WindsurfPhaser (web games)

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.