A MonoGame sample demonstrating network prediction and smoothing techniques to compensate for network latency and low packet send rates.
This sample shows how to use prediction and smoothing to compensate for the effects of network latency, and for the low packet send rates needed to conserve network bandwidth. The project has been modernized to use:
- .NET 8.0 SDK-style projects
- MonoGame 3.8.* NuGet packages
- NetRumble MonoGame.Xna.Framework.Net library for full XNA 4.0 networking compatibility
The project includes support for multiple platforms, each with its own folder and entry point:
- Windows (
Platforms/Windows/NetworkPrediction.Windows.csproj,Program.cs) - Uses DirectX backend - DesktopGL (
Platforms/Desktop/NetworkPrediction.DesktopGL.csproj,Program.cs) - Cross-platform OpenGL backend - Android (
Platforms/Android/NetworkPrediction.Android.csproj,Program.cs) - Android mobile platform - iOS (
Platforms/iOS/NetworkPrediction.iOS.csproj,Program.cs) - iOS mobile platform
All platform projects reference the shared core logic in Core/NetworkPrediction.Core.csproj.
Folder Structure:
NetworkPrediction.sln
README.md
Core/
NetworkPrediction.Core.csproj
NetworkPredictionGame.cs
RollingAverage.cs
Tank.cs
Content/
Platforms/
Windows/
NetworkPrediction.Windows.csproj
Program.cs
Desktop/
NetworkPrediction.DesktopGL.csproj
Program.cs
Android/
NetworkPrediction.Android.csproj
Program.cs
iOS/
NetworkPrediction.iOS.csproj
Program.cs
✅ Completed:
- Modernized all project files to SDK-style format
- Updated to use MonoGame 3.8.* NuGet packages
- Integrated NetRumble MonoGame.Xna.Framework.Net for full XNA 4.0 networking compatibility
- Consolidated all XNA networking APIs - no code duplication
- Created VS Code tasks and launch configurations
- Removed obsolete macOS project (no longer supported in MonoGame 3.8.*)
- Updated solution file with new project structure
- Fixed all critical build errors and platform compatibility issues
- All platforms build successfully (Windows, DesktopGL, Android, iOS)
✅ XNA 4.0 API Compatibility:
- Full Microsoft.Xna.Framework.GamerServices support (SignedInGamer, Guide, etc.)
- Full Microsoft.Xna.Framework.Net support (NetworkSession, NetworkGamer, PacketReader/Writer, etc.)
- All networking APIs match XNA 4.0 specifications
- Shared implementation eliminates duplicate code
- Content pipeline warnings (no .mgcb file, using prebuilt .xnb files - this is intentional)
- iOS platform compatibility warnings (CA1416 - informational only, builds successfully)
- Game.Exit() disabled on iOS per platform policy
- .NET 8.0 SDK or later
- Visual Studio 2022 or VS Code with C# extension
# Build Windows version
dotnet build NetworkPrediction.Windows.csproj
# Build DesktopGL version
dotnet build NetworkPrediction.DesktopGL.csproj
# Build Android version
dotnet build NetworkPrediction.Android.csproj
# Build iOS version
dotnet build NetworkPrediction.iOS.csproj
# Build all projects
dotnet build NetworkPrediction.slnOpen NetworkPrediction.sln in Visual Studio and build the solution.
Use the Command Palette (Ctrl+Shift+P) and run:
Tasks: Run Task→build-windowsorbuild-desktopglDebug: Start Debugging→ Choose "Launch Windows" or "Launch DesktopGL"
dotnet run --project NetworkPrediction.Windows.csprojdotnet run --project NetworkPrediction.DesktopGL.csprojUse platform-specific deployment tools (Android Studio, Xcode) or dotnet publish commands for mobile platforms.
The project uses pre-built XNB content files located in the Content/ directory:
Font.xnb- Sprite font for UI textTank.xnb- Tank sprite textureTurret.xnb- Turret sprite texture
- Arrow Keys / WASD - Move tank
- Mouse / Right Stick - Aim turret
- A - Create network session
- B - Join network session
- Escape - Exit game
The project uses the NetRumble MonoGame.Xna.Framework.Net library which provides a fully compatible implementation of the Microsoft.Xna.Framework.Net and Microsoft.Xna.Framework.GamerServices namespaces. This shared implementation:
- Maintains full XNA 4.0 API compatibility
- Eliminates code duplication across projects
- Provides all required networking classes (NetworkSession, NetworkGamer, PacketReader/Writer, etc.)
- Includes gamer services functionality (SignedInGamer, Guide, etc.)
The project follows a consolidated architecture:
- NetworkPrediction - Main game sample (this project)
- NetRumble\MonoGame.Xna.Framework.Net - Shared XNA 4.0 networking implementation
- No duplicate networking code between projects
To contribute to this project:
- Test networking functionality in real multiplayer scenarios
- Add additional platform-specific optimizations
- Enhance the prediction algorithms
- Add more comprehensive error handling
This project is based on the original Microsoft XNA Community Game Platform samples and follows the same licensing terms.