.NET Gaming API Reference
Welcome to the comprehensive API reference for the .NET Gaming Framework. This documentation provides detailed information on all classes, methods, properties, and enumerations available for developing high-performance, cross-platform games with .NET.
Overview
The .NET Gaming API is designed to offer a robust and flexible foundation for game development. It leverages the power and efficiency of the .NET runtime, enabling developers to create sophisticated games for various platforms.
Key features include:
- High-performance graphics rendering (DirectX, Vulkan, Metal support).
- Low-level input handling for keyboards, mice, gamepads, and touch.
- Multi-channel audio playback and management.
- Scene graph and entity-component system for organizing game objects.
- Integrated physics engine for realistic simulations.
- Extensible scripting capabilities.
- Comprehensive math library for 2D and 3D operations.
Graphics
The Graphics module provides tools for rendering 2D and 3D graphics. This includes managing render targets, shaders, textures, meshes, and post-processing effects.
Classes
Renderer: Manages the overall rendering pipeline.Shader: Represents and compiles shader programs.Texture: Loads and manages image assets.Mesh: Defines geometric data for 3D models.Material: Defines surface properties for meshes.
Key Methods
Renderer.DrawMesh(Mesh mesh, Material material, Matrix4x4 worldMatrix)
Example Usage
// Create a simple cube mesh
Mesh cubeMesh = Mesh.CreateCube();
// Load a basic material
Material diffuseMaterial = Material.Load("materials/basic.mat");
// Set up world transformation
Matrix4x4 objectTransform = Matrix4x4.CreateTranslation(0, 0, -5);
// Draw the cube
Graphics.Renderer.DrawMesh(cubeMesh, diffuseMaterial, objectTransform);
Input Management
The Input module handles user input from various devices. It provides an abstraction layer to access key presses, mouse movements, gamepad states, and touch events.
Classes
InputManager: Central hub for input events.KeyboardState: Represents the current state of the keyboard.MouseState: Represents the current state of the mouse.GamepadState: Represents the current state of a gamepad.
Events
InputManager.KeyPressed, InputManager.MouseButtonDown, InputManager.GamepadButtonPress
Example Usage
// Check if the 'W' key is pressed
if (Input.Keyboard.IsKeyDown(KeyCode.W))
{
// Move player forward
}
// Get mouse position
Vector2 mousePos = Input.Mouse.Position;
Audio
Manage audio playback, including loading sound effects and music, controlling volume, and spatializing audio sources.
Classes
AudioManager: Manages all audio operations.SoundEffect: Represents a short audio clip.MusicTrack: Represents a longer audio piece.
Methods
AudioManager.PlaySoundEffect(SoundEffect effect, Vector3 position = Vector3.Zero)
Example Usage
SoundEffect laserSound = SoundManager.LoadSound("sounds/laser.wav");
AudioManager.PlaySoundEffect(laserSound, player.Position);
Scene Management
Organize and manage game entities within a hierarchical scene graph. This module facilitates object transformations, culling, and spatial partitioning.
Classes
Scene: Represents the current game world.GameObject: A node in the scene graph.Transform: Manages position, rotation, and scale.
Methods
Scene.AddGameObject(GameObject obj), GameObject.AddComponent(Component comp)
Rendering Components
Components that can be attached to GameObjects to define their visual representation.
Classes
MeshRenderer: Renders aMesh.SpriteRenderer: Renders a 2D sprite.Camera: Defines the viewpoint for rendering.
Example Usage
GameObject player = new GameObject("Player");
player.AddComponent<MeshRenderer>().Mesh = Mesh.Load("models/player.obj");
player.AddComponent<PlayerController>(); // Custom script component
Scene.Active.AddGameObject(player);
Physics Engine
Provides capabilities for 2D and 3D physics simulations, including rigid bodies, colliders, and collision detection.
Classes
PhysicsManager: Manages physics simulations.Rigidbody: Adds physics properties to aGameObject.Collider: Defines collision shapes (Box, Sphere, Capsule).
Events
Rigidbody.OnCollisionEnter, Rigidbody.OnTriggerEnter
Scripting Interface
Allows developers to extend game behavior using a scripting language (e.g., C#, Lua via integration).
Classes
ScriptComponent: Base class for custom scripts.ScriptManager: Manages script execution and lifecycle.
Methods (in ScriptComponent)
Awake(), Start(), Update(), OnDestroy()
Math Library
A comprehensive set of math types and functions for game development.
Types
Vector2,Vector3,Vector4QuaternionMatrix3x3,Matrix4x4Color
Functions
Vector3.Normalize(Vector3 v), Matrix4x4.Multiply(Matrix4x4 a, Matrix4x4 b), Mathf.Sin(float angle)
Serialization
Utilities for saving and loading game state, assets, and configuration.
Classes
Serializer: Provides methods for serialization and deserialization (e.g., JSON, Binary).SaveGame: Represents a saved game state.
Methods
Serializer.ToJson(object obj), Serializer.FromJson<T>(string json)
Networking
Components and utilities for implementing multiplayer functionality.
Classes
NetworkManager: Manages network connections and messages.Connection: Represents a connection to another peer.Message: Represents a network message.
Events
NetworkManager.OnConnected, NetworkManager.OnDisconnected, NetworkManager.OnMessageReceived