### Install Prerequisites for Wine Setup Source: https://docs.monogame.net/articles/getting_started/1_setting_up_your_os_for_development_ubuntu.html Installs necessary packages (wget, curl, p7zip-full) required for setting up Wine for effect (shader) compilation on Linux. ```bash sudo apt install wget curl p7zip-full ``` -------------------------------- ### Install MGFXC .NET Tool Source: https://docs.monogame.net/articles/getting_started/tools/mgfxc.html Install the MGFXC tool globally using the .NET CLI. Ensure the .NET SDK is installed first. ```bash dotnet tool install -g dotnet-mgfxc ``` -------------------------------- ### Install .NET 9 SDK on Arch Linux Source: https://docs.monogame.net/articles/getting_started/1_setting_up_your_os_for_development_arch.html Installs the .NET 9 SDK using pacman. Ensure your system is up-to-date before installation. ```bash sudo pacman -Syu sudo pacman -S dotnet-sdk-9.0 ``` -------------------------------- ### Game.BeginRun Method Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Game.html Called after Initialize() and before the first Update(GameTime) call. Use this for setup that needs to occur after initialization but before the main game loop starts. ```csharp protected virtual void BeginRun() ``` -------------------------------- ### Install .NET Workloads for Android, iOS, and MAUI Source: https://docs.monogame.net/articles/getting_started/1_setting_up_your_os_for_development_windows.html Execute this command to install the .NET workloads for Android, iOS, and MAUI simultaneously. This is a comprehensive installation for mobile development support. ```bash dotnet workload install android ios maui ``` -------------------------------- ### Install WINE for Effect Compilation on Linux Source: https://docs.monogame.net/articles/tutorials/building_2d_games/02_getting_started/index.html Installs necessary tools and MonoGame's WINE setup script for effect compilation on Linux. Uses apt-get for package management. ```bash sudo apt-get update && sudo apt-get install -y curl p7zip-full wine64 wget -qO- https://monogame.net/downloads/net8_mgfxc_wine_setup.sh | bash ``` -------------------------------- ### Install Homebrew Dependencies and Wine Source: https://docs.monogame.net/articles/getting_started/1_setting_up_your_os_for_development_macos.html Installs necessary tools like wget, p7zip, and curl using Homebrew, then installs the stable Wine version and removes quarantine attributes from the application. ```bash brew install wget p7zip curl && brew install --cask wine-stable && xattr -dr com.apple.quarantine "/Applications/Wine Stable.app" ``` -------------------------------- ### Install .NET SDK on Linux Source: https://docs.monogame.net/articles/tutorials/building_2d_games/02_getting_started/index.html Use this command to install the .NET SDK on a Linux system. Ensure you have the correct version installed as per MonoGame requirements. ```bash sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0 ``` -------------------------------- ### SensorBase Start Method Source: https://docs.monogame.net/api/MonoGame.Framework.Devices.Sensors.SensorBase-1.html Abstract method that must be implemented by derived classes to start the sensor. ```csharp public abstract void Start() ``` -------------------------------- ### Install MGCB .NET Tool Source: https://docs.monogame.net/articles/getting_started/tools/mgcb.html Installs the MonoGame Content Builder as a global .NET tool. Ensure the .NET SDK is installed first. ```bash dotnet tool install -g dotnet-mgcb ``` -------------------------------- ### Example Response File Source: https://docs.monogame.net/articles/getting_started/tools/mgcb.html An example of a response file used with MGCB, specifying output and intermediate directories, and initiating a rebuild. ```bash # Directories /outputDir:bin/foo /intermediateDir:obj/foo /rebuild ``` -------------------------------- ### Example Command Line Arguments for ContentBuilderParams Source: https://docs.monogame.net/articles/getting_started/content_pipeline/content_builder_project.html Example of command line arguments that can be parsed by ContentBuilderParams.Parse(). ```bash mybuilder.exe --src "MyAssets" --output "bin/Content" --platform DesktopGL --compress ``` -------------------------------- ### Install MonoGame Preview Templates Source: https://docs.monogame.net/articles/getting_to_know/howto/HowTo_Install_Preview_Release.html Install the latest MonoGame C# project templates, including any preview versions. Replace the version number with the specific version you wish to install. ```bash dotnet new install MonoGame.Templates.CSharp::3.8.4-preview.1 ``` -------------------------------- ### macOS Info.plist example Source: https://docs.monogame.net/articles/getting_started/packaging_games.html This is an example of an Info.plist file for a macOS application bundle. It contains essential metadata about your game, such as its name, version, and icon. Ensure LSMinimumSystemVersion is set appropriately for your target audience. ```xml CFBundleDevelopmentRegion en CFBundleExecutable YourGame CFBundleIconFile YourGame CFBundleIdentifier com.your-domain.YourGame CFBundleInfoDictionaryVersion 6.0 CFBundleName YourGame CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature FONV CFBundleVersion 1 LSApplicationCategoryType public.app-category.games LSMinimumSystemVersion 10.15 NSHumanReadableCopyright Copyright © 2022 NSPrincipalClass NSApplication LSRequiresNativeExecution LSArchitecturePriority arm64 ``` -------------------------------- ### Install .NET Workload for Android Source: https://docs.monogame.net/articles/getting_started/1_setting_up_your_os_for_development_windows.html Run this command to install the .NET workload for Android development. This is necessary for building and debugging Android applications. ```bash dotnet workload install android ``` -------------------------------- ### TechniqueInfo Start Position Field Source: https://docs.monogame.net/api/MonoGame.Effect.TechniqueInfo.html Specifies the starting position or index of the technique. ```csharp public int startPos__ ``` -------------------------------- ### Install .NET Workload for iOS Source: https://docs.monogame.net/articles/getting_started/1_setting_up_your_os_for_development_windows.html Run this command to install the .NET workload for iOS development. This is required for building and debugging iOS applications. ```bash dotnet workload install ios ``` -------------------------------- ### Enable Default Lighting Setup Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.EnvironmentMapEffect.html Configures the effect to use a standard lighting setup, typically including key, fill, and back lights. This method simplifies scene lighting initialization. ```csharp public void EnableDefaultLighting() ``` -------------------------------- ### Get AnimationKeyframe Time Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Graphics.AnimationKeyframe.html Gets the time offset from the start of the animation to the position described by this keyframe. ```csharp public TimeSpan Time { get; } ``` -------------------------------- ### Initialize AudioEngine with Settings File Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Audio.AudioEngine.html Initializes the AudioEngine by loading XACT settings from a specified file. Ensure the settings file path is valid to avoid exceptions. ```csharp public AudioEngine(string settingsFile) ``` -------------------------------- ### AudioContent.LoopStart Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Audio.AudioContent.html Gets the current loop start location in samples. This value can change from the source loop start after conversion. ```csharp public int LoopStart { get; } ``` -------------------------------- ### Install .NET Workload Source: https://docs.monogame.net/articles/getting_started/content_pipeline/automating_content_builder.html Installs a specific .NET workload if defined for the current build matrix. This is necessary for certain platform targets like iOS or Android. ```bash - name: Install workload if: ${{ matrix.workload != '' }} run: dotnet workload install ${{ matrix.workload }} ``` -------------------------------- ### Create a Simple ImGui Window Source: https://docs.monogame.net/articles/tutorials/advanced/2d_shaders/04_debug_ui/index.html Add ImGui.Begin(), ImGui.Text(), and ImGui.End() calls between BeforeLayout and AfterLayout to create a basic ImGui window. This example creates a window titled 'Demo Window' displaying 'Hello world!'. ```csharp protected override void Draw(GameTime gameTime) { // ... // Draw debug UI Core.ImGuiRenderer.BeforeLayout(gameTime); ImGui.Begin("Demo Window"); ImGui.Text("Hello world!"); ImGui.End(); // Finish drawing the debug UI here Core.ImGuiRenderer.AfterLayout(); base.Draw(gameTime); } ``` -------------------------------- ### Install WINE for Effect Compilation on macOS Source: https://docs.monogame.net/articles/tutorials/building_2d_games/02_getting_started/index.html Installs necessary tools and MonoGame's WINE setup script for effect compilation on macOS. Requires Homebrew. ```bash brew install p7zip brew install --cask wine-stable xattr -dr com.apple.quarantine "/Applications/Wine Stable.app" wget -qO- https://monogame.net/downloads/net8_mgfxc_wine_setup.sh | bash ``` -------------------------------- ### Initialize() Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Audio.SoundEffect.html Initializes the sound system for SoundEffect support. ```APIDOC ## Initialize() ### Description Initializes the sound system for SoundEffect support. This method is automatically called when a SoundEffect is loaded, a DynamicSoundEffectInstance is created, or Microphone.All is queried. You can however call this method manually (preferably in, or before the Game constructor) to catch any Exception that may occur during the sound system initialization (and act accordingly). ### Method `public static void Initialize()` ``` -------------------------------- ### Load Sound and Create Instance Source: https://docs.monogame.net/articles/getting_to_know/howto/audio/HowTo_ChangePitchAndVolume.html Load a sound file and create a SoundEffectInstance in the Game.LoadContent method. Ensure the sound file's 'Build Action' is set to 'COPY' in the MGCB tool to access its raw stream. ```csharp using Stream soundfile = TitleContainer.OpenStream(@"Content\tx0_fire1.wav"); soundEffect = SoundEffect.FromStream(soundfile); soundEffectInstance = soundEffect.CreateInstance(); ``` -------------------------------- ### Get IndexBuffer Data with Start Index and Count Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.IndexBuffer.html Copies index buffer data into an array, starting from a specified element index and for a specified number of elements. This is useful for partial retrieval. ```csharp public void GetData(T[] data, int startIndex, int elementCount) where T : struct ``` -------------------------------- ### Initialize GameScene Method Source: https://docs.monogame.net/articles/tutorials/building_2d_games/23_completing_the_game/index.html Sets up the initial state of the game scene, including disabling exit on escape, defining the playable area, subscribing to events, initializing UI, and starting a new game. ```csharp public override void Initialize() { // LoadContent is called during base.Initialize(). base.Initialize(); // During the game scene, we want to disable exit on escape. Instead, // the escape key will be used to return back to the title screen. Core.ExitOnEscape = false; // Create the room bounds by getting the bounds of the screen then // using the Inflate method to "Deflate" the bounds by the width and // height of a tile so that the bounds only covers the inside room of // the dungeon tilemap. _roomBounds = Core.GraphicsDevice.PresentationParameters.Bounds; _roomBounds.Inflate(-_tilemap.TileWidth, -_tilemap.TileHeight); // Subscribe to the slime's BodyCollision event so that a game over // can be triggered when this event is raised. _slime.BodyCollision += OnSlimeBodyCollision; // Create any UI elements from the root element created in previous // scenes. GumService.Default.Root.Children.Clear(); // Initialize the user interface for the game scene. InitializeUI(); // Initialize a new game to be played. InitializeNewGame(); } ``` -------------------------------- ### Set DualTextureEffect Fog Start Distance Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.DualTextureEffect.html Gets or sets the distance at which fog effects begin to appear in the DualTextureEffect. ```csharp public float FogStart { get; set; } ``` -------------------------------- ### Get DirectionalLight2 Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.IEffectLights.html Provides access to the third directional light in the lighting setup. Returns a DirectionalLight object. ```csharp DirectionalLight DirectionalLight2 { get; } ``` -------------------------------- ### Get DirectionalLight1 Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.IEffectLights.html Provides access to the second directional light in the lighting setup. Returns a DirectionalLight object. ```csharp DirectionalLight DirectionalLight1 { get; } ``` -------------------------------- ### Initialize Default Lighting Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.BasicEffect.html Initializes the lights to the standard key/fill/back lighting rig. Use this to set up a basic lighting environment. ```csharp public void EnableDefaultLighting()__ ``` -------------------------------- ### Get DirectionalLight0 Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.IEffectLights.html Provides access to the first directional light in the lighting setup. Returns a DirectionalLight object. ```csharp DirectionalLight DirectionalLight0 { get; } ``` -------------------------------- ### Initialize Camera and Projection Matrices Source: https://docs.monogame.net/articles/getting_to_know/howto/graphics/HowTo_Draw_3D_Primitives.html Sets up the world, view, and projection matrices for rendering 3D primitives. Uses an orthographic projection and calculates a translation matrix to center the primitives on the screen. ```csharp // Matrix to translate the drawn primitives to the center of the screen. private Matrix translationMatrix; // Number of vertex points to draw the primitive with. private int points = 8; // The length of the primitive lines to draw. private int lineLength = 100; protected override void Initialize() { worldMatrix = Matrix.Identity; viewMatrix = Matrix.CreateLookAt( new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up ); projectionMatrix = Matrix.CreateOrthographicOffCenter( 0, (float)GraphicsDevice.Viewport.Width, (float)GraphicsDevice.Viewport.Height, 0, 1.0f, 1000.0f); // Calculate the center of the visible screen using the ViewPort. Vector2 screenCenter = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); // Calculate the center of the primitives to be drawn. var primitiveCenter = new Vector2((points / 2 - 1) * lineLength / 2, lineLength / 2); // Create a translation matrix to position the drawn primitives in the center of the screen and the center of the primitives. translationMatrix = Matrix.CreateTranslation(screenCenter.X - primitiveCenter.X, screenCenter.Y - primitiveCenter.Y, 0); base.Initialize(); } ``` -------------------------------- ### GestureSample Timestamp Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.Touch.GestureSample.html Gets the starting time for this multi-touch gesture sample. Use this to track the timing of gesture events. ```csharp public TimeSpan Timestamp { get; } ``` -------------------------------- ### Initialize PreparingDeviceSettingsEventArgs Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.PreparingDeviceSettingsEventArgs.html Creates a new instance of the PreparingDeviceSettingsEventArgs class. Requires GraphicsDeviceInformation. ```csharp public PreparingDeviceSettingsEventArgs(GraphicsDeviceInformation graphicsDeviceInformation)__ ``` -------------------------------- ### ModelMeshPart StartIndex Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.ModelMeshPart.html Gets the location in the index array at which to start reading vertices. This is useful for drawing only a portion of the indexed geometry. ```csharp public int StartIndex { get; set; } ``` -------------------------------- ### Handle Start Button Click in Monogame Source: https://docs.monogame.net/articles/tutorials/building_2d_games/20_implementing_ui_with_gum/index.html Implement this method to handle clicks on the 'Start' button. It plays a sound effect and transitions the game to the 'GameScene'. ```csharp private void HandleStartClicked(object sender, EventArgs e) { // A UI interaction occurred, play the sound effect Core.Audio.PlaySoundEffect(_uiSoundEffect); // Change to the game scene to start the game. Core.ChangeScene(new GameScene()); } ``` -------------------------------- ### Install Wine and Dependencies on Arch Linux Source: https://docs.monogame.net/articles/getting_started/1_setting_up_your_os_for_development_arch.html Installs Wine and essential dependencies required for shader compilation on Linux systems. This includes wget, curl, 7zip, and wine. ```bash sudo pacman -S wget curl 7zip wine ``` -------------------------------- ### TotalGameTime Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.GameTime.html Gets or sets the total time elapsed since the start of the Game. This property tracks the overall duration of the game's execution. ```csharp public TimeSpan TotalGameTime { get; set; } ``` -------------------------------- ### Set First Character Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Processors.FontTextureProcessor.html Gets or sets the first character of the font. This property is used to define the starting character for font texture processing. ```csharp public virtual char FirstCharacter { get; set; } ``` -------------------------------- ### Initialize New Game Logic Source: https://docs.monogame.net/articles/tutorials/building_2d_games/23_completing_the_game/index.html Sets up a new game by positioning and initializing game entities like the slime and bat, resetting the score, and setting the game state to playing. ```csharp private void InitializeNewGame() { // Calculate the position for the slime, which will be at the center // tile of the tile map. Vector2 slimePos = new Vector2(); slimePos.X = (_tilemap.Columns / 2) * _tilemap.TileWidth; slimePos.Y = (_tilemap.Rows / 2) * _tilemap.TileHeight; // Initialize the slime. _slime.Initialize(slimePos, _tilemap.TileWidth); // Initialize the bat. _bat.RandomizeVelocity(); PositionBatAwayFromSlime(); // Reset the score. _score = 0; // Set the game state to playing. _state = GameState.Playing; } ``` -------------------------------- ### MouseState.ScrollWheelValue Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.MouseState.html Gets the cumulative scroll wheel value since the game started. To capture delta, compare current value to the previous frame's value. ```csharp public int ScrollWheelValue { get; } ``` -------------------------------- ### VertexElement UsageIndex Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.VertexElement.html Gets or sets the semantic index. Usage indices usually start with 0 and are adjusted internally by MonoGame when multiple vertex buffers are bound. ```csharp public int UsageIndex { get; set; } ``` -------------------------------- ### Initialize Sprite Variables and Load Content Source: https://docs.monogame.net/articles/getting_to_know/howto/graphics/HowTo_Scale_Sprites_Matrix.html Set up necessary variables for sprites, viewport, and scaling matrix, then load content including creating a debug texture and defining sprite positions. ```csharp private Viewport viewport; private Vector2[] scalingSpritePositions; private Texture2D squareTexture; private Vector2 spriteOrigin; private Matrix spriteScaleMatrix; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); viewport = _graphics.GraphicsDevice.Viewport; squareTexture = CreateTexture(GraphicsDevice, 50, 50); spriteOrigin = new Vector2(squareTexture.Width / 2, squareTexture.Height / 2); scalingSpritePositions = new Vector2[4]; scalingSpritePositions[0] = new Vector2(25, 25); scalingSpritePositions[1] = new Vector2(25, viewport.Height - 25); scalingSpritePositions[2] = new Vector2(viewport.Width - 25, 25); scalingSpritePositions[3] = new Vector2(viewport.Width - 25, viewport.Height - 25); UpdateScaleMatrix(); base.LoadContent(); } ``` -------------------------------- ### MonoGame Installation Instructions Template Source: https://docs.monogame.net/articles/tutorials/building_2d_games/26_publish_to_itch/index.html Provides platform-specific steps for extracting and running a MonoGame project distributed as an archive. Includes commands for setting executable permissions on Linux and macOS. ```text Once the download has completed: For Windows: 1. Extract the contents of the ZIP archive. 2. Run the "[YourGameName].exe" executable from the extracted folder. For Linux: 1. Extract the contents of the tar.gz archive. 2. Run the "[YourGameName]" executable from the extracted folder. 3. If the game does not open or states it is not executable, you may need to change the file permissions. To do this: 1. Open a terminal in the extracted directory. 2. Make the game executable with the command: chmod +x ./[YourGameName] For macOS: 1. Extract the contents of the tar.gz archive. 2. Run the [YourGameName].app executable from the extracted folder. 3. If the game does not open or states it is not an executable, you may need to change the file permissions. To do this: 1. Open a terminal in the extracted directory. 2. Make the game executable with the command: chmod +x ./[YourGameName].app/Contents/MacOS/[YourGameName] __ ``` -------------------------------- ### Get IndexBuffer Data with Offset Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.IndexBuffer.html Copies index buffer data into an array, starting from a specified byte offset. Use this when you need to retrieve a portion of the index buffer. ```csharp public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct ``` -------------------------------- ### Get Mouse State Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.Mouse.html Retrieves the current state of the mouse, including position and button presses for the primary window. No specific setup is required beyond having a game window. ```csharp public static MouseState GetState()__ ``` -------------------------------- ### MouseState.HorizontalScrollWheelValue Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.MouseState.html Gets the cumulative horizontal scroll wheel value since the game started. To capture delta, compare current value to the previous frame's value. ```csharp public int HorizontalScrollWheelValue { get; } ``` -------------------------------- ### Initialize Game and Load Assets Source: https://docs.monogame.net/articles/tutorials/building_2d_games/10_handling_input/index.html Sets up the game window and loads sprite assets from a texture atlas. This is typically done once at the start of the game. ```csharp using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using MonoGameLibrary; using MonoGameLibrary.Graphics; namespace DungeonSlime; public class Game1 : Core { // Defines the slime animated sprite. private AnimatedSprite _slime; // Defines the bat animated sprite. private AnimatedSprite _bat; // Tracks the position of the slime. private Vector2 _slimePosition; // Speed multiplier when moving. private const float MOVEMENT_SPEED = 5.0f; public Game1() : base("Dungeon Slime", 1280, 720, false) { } protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } protected override void LoadContent() { // Create the texture atlas from the XML configuration file. TextureAtlas atlas = TextureAtlas.FromFile(Content, "images/atlas-definition.xml"); // Create the slime animated sprite from the atlas. _slime = atlas.CreateAnimatedSprite("slime-animation"); _slime.Scale = new Vector2(4.0f, 4.0f); // Create the bat animated sprite from the atlas. _bat = atlas.CreateAnimatedSprite("bat-animation"); _bat.Scale = new Vector2(4.0f, 4.0f); } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); // Update the slime animated sprite. _slime.Update(gameTime); // Update the bat animated sprite. _bat.Update(gameTime); // Check for keyboard input and handle it. CheckKeyboardInput(); // Check for gamepad input and handle it. CheckGamePadInput(); base.Update(gameTime); } private void CheckKeyboardInput() { // Get the state of keyboard input KeyboardState keyboardState = Keyboard.GetState(); // If the space key is held down, the movement speed increases by 1.5 float speed = MOVEMENT_SPEED; if (keyboardState.IsKeyDown(Keys.Space)) { speed *= 1.5f; } // If the W or Up keys are down, move the slime up on the screen. if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up)) { _slimePosition.Y -= speed; } // if the S or Down keys are down, move the slime down on the screen. if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down)) { _slimePosition.Y += speed; } // If the A or Left keys are down, move the slime left on the screen. if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left)) { _slimePosition.X -= speed; } // If the D or Right keys are down, move the slime right on the screen. if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right)) { _slimePosition.X += speed; } } private void CheckGamePadInput() { GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); // If the A button is held down, the movement speed increases by 1.5 // and the gamepad vibrates as feedback to the player. float speed = MOVEMENT_SPEED; if (gamePadState.IsButtonDown(Buttons.A)) { speed *= 1.5f; GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f); } else { GamePad.SetVibration(PlayerIndex.One, 0.0f, 0.0f); } // Check thumbstick first since it has priority over which gamepad input // is movement. It has priority since the thumbstick values provide a // more granular analog value that can be used for movement. if (gamePadState.ThumbSticks.Left != Vector2.Zero) { _slimePosition.X += gamePadState.ThumbSticks.Left.X * speed; _slimePosition.Y -= gamePadState.ThumbSticks.Left.Y * speed; } else { // If DPadUp is down, move the slime up on the screen. ``` -------------------------------- ### Get TextureCube Data (Specified Count) Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.TextureCube.html Copies a specified number of elements from a texture cube face into an array, starting at a given index. The generic type T must be a struct. ```csharp public void GetData(CubeMapFace cubeMapFace, T[] data, int startIndex, int elementCount) where T : struct ``` -------------------------------- ### Start Mesh Creation Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Graphics.MeshBuilder.html Initializes the mesh building process. Use this method to begin creating a new mesh and obtain an object to manage its construction. ```csharp public static MeshBuilder StartMesh(string name) ``` -------------------------------- ### Direct Property Assignment Example Source: https://docs.monogame.net/articles/tutorials/building_2d_games/20_implementing_ui_with_gum/index.html Demonstrates changing a UI element's property directly in code. This method is suitable for initial setup, such as setting element positions or dimensions. ```csharp startButton.Width = 100; ``` -------------------------------- ### Get Vertex Data (Offset) Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.VertexBuffer.html Retrieves vertex data from the VertexBuffer starting at a specified byte offset. This operation is expensive as it transfers data from VRAM to main memory. Consider maintaining a copy of the data in main memory. ```csharp public void GetData(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride = 0) where T : struct ``` -------------------------------- ### Call EnableDefaultLighting Method Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.IEffectLights.html Initializes the lights to a standard key/fill/back lighting configuration. This method sets up default lighting rig. ```csharp void EnableDefaultLighting() ``` -------------------------------- ### Get Texture Data (With Offset and Count) Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.Texture3D.html Copies a specified number of texture data elements into an array, starting from a given index. The startIndex and elementCount must be valid within the array bounds and texture dimensions. The data array must not be null. ```csharp public void GetData(T[] data, int startIndex, int elementCount) where T : struct__ ``` -------------------------------- ### Initialize SoundEffectProcessor Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Processors.SoundEffectProcessor.html Constructs a new instance of the SoundEffectProcessor. No specific setup is required for basic initialization. ```csharp public SoundEffectProcessor() ``` -------------------------------- ### Implement StartLightPhase Method Source: https://docs.monogame.net/articles/tutorials/advanced/2d_shaders/08_light_effect/index.html Create a method to switch MonoGame's rendering target to the LightBuffer and clear it with black. This prepares the buffer for drawing light information. ```csharp public void StartLightPhase() { // all future draw calls will be drawn to the light buffer Core.GraphicsDevice.SetRenderTarget(LightBuffer); Core.GraphicsDevice.Clear(Color.Black); } ``` -------------------------------- ### EnableDefaultLighting() Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.BasicEffect.html Initializes the lights to the standard key/fill/back lighting rig. ```APIDOC ## EnableDefaultLighting() ### Description Initializes the lights to the standard key/fill/back lighting rig. ### Method public void ### Endpoint N/A (Method within a class) ### Parameters None ### Request Example None ### Response None ``` -------------------------------- ### Build .NET Project Source: https://docs.monogame.net/articles/getting_started/content_pipeline/automating_content_builder.html Builds the .NET project with the specified configuration and runtime. This compiles the game code. ```bash - name: Build run: dotnet build -c ${{ env.Configuration }} ${{ matrix.project }} -r ${{ matrix.runtime }} ``` -------------------------------- ### EffectTechnique Examples Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.EffectTechnique.html Code examples demonstrating how to use the EffectTechnique class. ```APIDOC ## Examples 1. Create an **EffectTechnique** for each technique in your Effect. ```csharp public EffectTechnique texture; public EffectTechnique shadows; public EffectTechnique shadowMap; ``` 2. Assign an Effect technique to your **EffectTechnique**. ```csharp texture = effect.Techniques["TextureRender"]; shadowMap = effect.Techniques["ShadowMapRender"]; shadows = effect.Techniques["ShadowRender"]; ``` 3. Assign your **EffectTechnique** to the CurrentTechnique of your Effect before drawing. ```csharp private void DrawScene(EffectTechnique technique) { MyEffect.mWorld.SetValue(terrainWorld); MyEffect.MeshTexture.SetValue(terrainTex); foreach (ModelMesh mesh in terrain.Meshes) { foreach (Effect effect in mesh.Effects) { effect.CurrentTechnique = technique; mesh.Draw(); } } } ``` ## Remarks Creating and assigning an **EffectTechnique** instance for each technique in your Effect is significantly faster than using the Techniques indexed property on Effect. ``` -------------------------------- ### Initialize Point Light List Source: https://docs.monogame.net/articles/tutorials/advanced/2d_shaders/08_light_effect/index.html Initialize a list to hold PointLight objects and add a debug light for initial testing. This sets up the lights to be rendered. ```csharp // A list of point lights to be rendered private List _lights = new List(); public override void Initialize() { // ... _lights.Add(new PointLight { Position = new Vector2(300, 300) }); } ``` -------------------------------- ### Get SoundEffectInstance State Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Audio.DynamicSoundEffectInstance.html Gets the current playback state of the SoundEffectInstance. ```csharp public override SoundState State { get; } ``` -------------------------------- ### Initialize SongProcessor Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Processors.SongProcessor.html Constructor for the SongProcessor class. No specific setup is required beyond instantiation. ```csharp public SongProcessor() ``` -------------------------------- ### Install AUR Helper (yay) on Arch Linux Source: https://docs.monogame.net/articles/getting_started/2_choosing_your_ide_vscode.html Installs the 'yay' AUR helper, which is required to install packages from the Arch User Repository, such as the official Visual Studio Code. ```bash sudo pacman -S git base-devel git clone https://aur.archlinux.org/yay.git cd yay makepkg -si ``` -------------------------------- ### Initialize Sound System Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Audio.SoundEffect.html Initializes the sound system for SoundEffect support. It's recommended to call this manually before the Game constructor to handle potential exceptions. ```csharp public static void Initialize()__ ``` -------------------------------- ### Initialize KeyboardInfo Class Structure Source: https://docs.monogame.net/articles/tutorials/building_2d_games/11_input_management/index.html Sets up the basic structure for the KeyboardInfo class, including necessary namespaces and the class definition. ```csharp using Microsoft.Xna.Framework.Input; namespace MonoGameLibrary.Input; public class KeyboardInfo { } ``` -------------------------------- ### Get Vector4 Representation of Color Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Color.html Gets a Vector4 representation for the Color object. ```csharp public Vector4 ToVector4()__ ``` -------------------------------- ### Get Vector3 Representation of Color Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Color.html Gets a Vector3 representation for the Color object. ```csharp public Vector3 ToVector3()__ ``` -------------------------------- ### Line Strip Index Example Source: https://docs.monogame.net/articles/getting_to_know/howto/graphics/HowTo_Draw_3D_Primitives.html An alternative manual initialization of the line strip index array, showing a series of connected lines. ```csharp lineStripIndices = new short[8]{ 0, 1, 2, 3, 4, 5, 6, 7 }; ``` -------------------------------- ### Get CommandLineParser Title Source: https://docs.monogame.net/api/MonoGame.Effect.CommandLineParser.html Property to get or set the title of the command line parser. ```csharp public string Title { get; set; }__ ``` -------------------------------- ### SamplerState Constructors Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.SamplerState.html Details on how to create new instances of the SamplerState class. ```APIDOC ## Constructors ### SamplerState() #### Description Creates a new instance of the SamplerState class with default values equivalent to LinearWrap. ```csharp public SamplerState() ``` ``` -------------------------------- ### Build Intel (x64) macOS Application Source: https://docs.monogame.net/articles/tutorials/building_2d_games/25_packaging_game/index.html Use this .NET CLI command to create a self-contained application for Intel (x64) macOS. Ensure you are in the project's root directory. ```bash dotnet publish -c Release -r osx-x64 -p:PublishReadyToRun=false -p:TieredCompilation=false --self-contained ``` -------------------------------- ### Get Target Type Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentTypeWriter.html Gets the type handled by this compiler component. This is set during initialization. ```csharp public Type TargetType { get; } ``` -------------------------------- ### Install MonoGame Templates via .NET CLI Source: https://docs.monogame.net/articles/getting_started/2_choosing_your_ide_rider.html Use this command in your terminal to install the MonoGame C# project templates globally. This is necessary if Rider's automatic installation fails due to a known bug. ```bash dotnet new install MonoGame.Templates.CSharp ``` -------------------------------- ### Initialize Game State Variables Source: https://docs.monogame.net/articles/tutorials/building_2d_games/14_soundeffects_and_music/index.html Sets up initial positions and bounds for game elements like the slime, bat, and room boundaries based on screen and tilemap dimensions. ```csharp base.Initialize(); Rectangle screenBounds = GraphicsDevice.PresentationParameters.Bounds; _roomBounds = new Rectangle( (int)_tilemap.TileWidth, (int)_tilemap.TileHeight, screenBounds.Width - (int)_tilemap.TileWidth * 2, screenBounds.Height - (int)_tilemap.TileHeight * 2 ); // Initial slime position will be the center tile of the tile map. int centerRow = _tilemap.Rows / 2; int centerColumn = _tilemap.Columns / 2; _slimePosition = new Vector2(centerColumn * _tilemap.TileWidth, centerRow * _tilemap.TileHeight); // Initial bat position will the in the top left corner of the room _batPosition = new Vector2(_roomBounds.Left, _roomBounds.Top); // Assign the initial random velocity to the bat. AssignRandomBatVelocity(); ``` -------------------------------- ### WindowsDX Texture Access Example Source: https://docs.monogame.net/articles/tutorials/advanced/2d_shaders/09_shadows_effect/index.html Example of accessing textures in WindowsDX using the Sample method. ```hlsl float4 normal = NormalBuffer.Sample(NormalBufferSampler, screenCoords); float shadow = ShadowBuffer.Sample(ShadowBufferSampler, screenCoords).r; __ ``` -------------------------------- ### Get Type Version Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentTypeWriter.html Gets a format version number for this type. This is used for serialization compatibility. ```csharp public virtual int TypeVersion { get; } ``` -------------------------------- ### Handle PreparingDeviceSettings Event Source: https://docs.monogame.net/articles/getting_to_know/whatis/graphics/WhatIs_3DRendering.html Adjust presentation parameters like back buffer width and height by handling the PreparingDeviceSettings event on the GraphicsDeviceManager. Changes here override preferred settings. ```csharp _graphics.PreparingDeviceSettings += OnPreparingDeviceSettings; private void OnPreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e) { e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = 1024; e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = 768; } ``` -------------------------------- ### Get and Set AnimationKeyframe Transform Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Graphics.AnimationKeyframe.html Gets or sets the transformation matrix representing the position of the keyframe. ```csharp public Matrix Transform { get; set; } ``` -------------------------------- ### AudioEngine Constructors Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Audio.AudioEngine.html Initializes a new instance of the AudioEngine class. ```APIDOC ## AudioEngine(string) ### Description Initializes a new instance of the AudioEngine class by reading out the specified XACT `settingsFile`. ### Method `public AudioEngine(string settingsFile)` ### Parameters #### Path Parameters - **settingsFile** (string) - Required - Path to a XACT settings file. #### Exceptions - **ArgumentException** - Invoked if `settingsFile` is IsNullOrEmpty(string) ## AudioEngine(string, TimeSpan, string) ### Description Initializes a new instance of the AudioEngine class by reading out the specified XACT `settingsFile`. ### Method `[Obsolete("Use AudioEngine(string settingsFile) instead. The lookAheadTime and rendererId parameters are not used.")] public AudioEngine(string settingsFile, TimeSpan lookAheadTime, string rendererId)` ### Parameters #### Path Parameters - **settingsFile** (string) - Required - Path to a XACT settings file. - **lookAheadTime** (TimeSpan) - Required - `Not in use:` use the AudioEngine(string) constructor instead! - **rendererId** (string) - Required - `Not in use:` use the AudioEngine(string) constructor instead! ``` -------------------------------- ### Game.Initialize Method Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Game.html Override this method to initialize game systems and load non-graphical resources. It also initializes attached GameComponents and calls LoadContent(). ```csharp protected virtual void Initialize() ``` -------------------------------- ### Get GamePad Triggers State Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.GamePadState.html Gets a structure that identifies the position of triggers on the controller. This property is read-only. ```csharp public readonly GamePadTriggers Triggers { get; } ``` -------------------------------- ### GamePadInfo Constructor Source: https://docs.monogame.net/articles/tutorials/building_2d_games/11_input_management/index.html Initializes a new GamePadInfo instance, setting the player index, an empty previous state, and the current gamepad state. ```csharp /// /// Creates a new GamePadInfo for the gamepad connected at the specified player index. /// /// The index of the player for this gamepad. public GamePadInfo(PlayerIndex playerIndex) { PlayerIndex = playerIndex; PreviousState = new GamePadState(); CurrentState = GamePad.GetState(playerIndex); } ``` -------------------------------- ### Enable and Handle Window Resizing Source: https://docs.monogame.net/articles/getting_to_know/howto/HowTo_PlayerResize.html Set Game.GameWindow.AllowUserResizing to true and add an event handler for the ClientSizeChanged event. ```csharp this.Window.AllowUserResizing = true; this.Window.ClientSizeChanged += new EventHandler(Window_ClientSizeChanged); ``` ```csharp void Window_ClientSizeChanged(object sender, EventArgs e) { // Make changes to handle the new window size. } ``` -------------------------------- ### Get GamePad State Packet Number Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.GamePadState.html Gets the packet number associated with this state. This property is read-only. ```csharp public readonly int PacketNumber { get; } ``` -------------------------------- ### SamplerState Class Overview Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Graphics.SamplerState.html Provides information about the SamplerState class, its namespace, assembly, and inheritance hierarchy. ```APIDOC ## Class SamplerState Namespace Microsoft.Xna.Framework.Graphics Assembly MonoGame.Framework.dll ### Description Contains sampler state, which determines how to sample texture data. ```csharp public class SamplerState : GraphicsResource, IDisposable ``` ### Inheritance - object - GraphicsResource - SamplerState ### Implements - IDisposable ### Inherited Members - GraphicsResource.GraphicsDeviceResetting() - GraphicsResource.Dispose() - GraphicsResource.Disposing - GraphicsResource.GraphicsDevice - GraphicsResource.IsDisposed - GraphicsResource.Name - GraphicsResource.Tag - GraphicsResource.ToString() - object.Equals(object) - object.Equals(object, object) - object.GetHashCode() - object.GetType() - object.MemberwiseClone() - object.ReferenceEquals(object, object) ``` -------------------------------- ### Get GamePad Buttons State Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.GamePadState.html Gets a structure that identifies what buttons on the controller are pressed. This property is read-only. ```csharp public readonly GamePadButtons Buttons { get; } ``` -------------------------------- ### Get TargetProfile - ContentWriter Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.html Gets or sets the target graphics profile for content compilation. This property is read-only. ```csharp public GraphicsProfile TargetProfile { get; } ``` -------------------------------- ### Get Green Component Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Color.html Gets or sets the green component of a color. This property is part of the Color structure. ```csharp [DataMember] public byte G { get; set; } ``` -------------------------------- ### Start Network Content Server Listening Source: https://docs.monogame.net/api/MonoGame.Framework.Content.Pipeline.Builder.Server.NetworkContentServer.html Initiates the content server to begin listening for requests. This method is called by the main thread and must be non-blocking. ```csharp public override void StartListening() ``` -------------------------------- ### Get SoundEffectInstance Playback State Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Audio.SoundEffectInstance.html Gets the current playback state (Playing, Paused, Stopped) of the SoundEffectInstance. ```csharp public virtual SoundState State { get; } ``` -------------------------------- ### Initialize Lights and ShadowCaster Source: https://docs.monogame.net/articles/tutorials/advanced/2d_shaders/09_shadows_effect/index.html Temporarily replaces the `InitializeLights()` function in `GameScene` to set up a single `PointLight` and a single `ShadowCaster` for basic testing purposes. ```csharp private void InitializeLights() { // torch 1 _lights.Add(new PointLight { Position = new Vector2(500, 360), Color = Color.CornflowerBlue, Radius = 700 }); // simple shadow caster _shadowCasters.Add(new ShadowCaster { A = new Vector2(700, 320), B = new Vector2(700, 400) }); } ``` -------------------------------- ### Get AudioCategory Hash Code Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Audio.AudioCategory.html Gets the hash code for the current AudioCategory instance. Useful for collections. ```csharp public override int GetHashCode() ``` -------------------------------- ### SoundBank Constructor Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Audio.SoundBank.html Initializes a new instance of the SoundBank class. Requires an AudioEngine instance and the path to the .xsb sound bank file. ```csharp public SoundBank(AudioEngine audioEngine, string fileName) ``` -------------------------------- ### Get or Set Random Number Generator State Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.MathHelper.Random.html Gets or sets the current state of the random number generator. ```csharp public ulong State { get; set; } ``` -------------------------------- ### Game.LaunchParameters Property Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Game.html Provides access to the startup parameters used when the game was launched. This property is read-only. ```csharp public LaunchParameters LaunchParameters { get; } ``` -------------------------------- ### Get GamePad Thumbsticks State Source: https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.GamePadState.html Gets a structure that indicates the position of the controller sticks (thumbsticks). This property is read-only. ```csharp public readonly GamePadThumbSticks ThumbSticks { get; } ``` -------------------------------- ### Initial AudioController Class Structure Source: https://docs.monogame.net/articles/tutorials/building_2d_games/15_audio_controller/index.html Sets up the basic structure for the AudioController class, implementing the IDisposable interface for resource management. ```csharp using System; using System.Collections.Generic; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Media; namespace MonoGameLibrary.Audio; public class AudioController : IDisposable { } ``` -------------------------------- ### Accelerometer Start Method Source: https://docs.monogame.net/api/MonoGame.Framework.Devices.Sensors.Accelerometer.html Starts data acquisition from the accelerometer. This method is part of the sensor's active operation. ```csharp public override void Start() ``` -------------------------------- ### Example Code Block Source: https://docs.monogame.net/articles/tutorials/building_2d_games Code blocks are used to display multi-line code examples with syntax highlighting for improved readability. ```csharp // Example Code Block public void Foo() { } ``` -------------------------------- ### Loading Assets with the Content Pipeline Source: https://docs.monogame.net/articles/tutorials/building_2d_games/05_content_pipeline/index.html This workflow involves adding assets to your content project (_Content.mgcb_ file), building the project to compile them into an optimized format for the target platform, and then loading them at runtime using the ContentManager. This method offers benefits like GPU-compatible compression formats and reduced memory usage. ```csharp MonoGame.Content.Builder.Tasks ``` ```csharp ContentManager ```