title | description | ms.prod | ms.assetid | ms.date |
---|---|---|---|---|
The MonoGame Pipeline Tool is used to create and manage MonoGame content projects. The files in content projects are processed by the MonoGame Pipeline tool and outputted as .xnb files for use in CocosSharp and MonoGame applications. | CACFBF5F-BBD4-4D46-8DDA-1F46466725FD |
The MonoGame Pipeline Tool is used to create and manage MonoGame content projects. The files in content projects are processed by the MonoGame Pipeline tool and outputted as .xnb files for use in CocosSharp and MonoGame applications.
However, when Visual Studio 2017 was install on its own or on a clean machine, the templates would simply not work. A fix has already been delivered but it was after the MonoGame 3.6 release. To use Visual Studio 2017 on its own, use the current Development release of MonoGame until a point release is submitted. There is currently very little difference between 3.6 and the development release, so it's completely fine. Syntax highlighting in visual studio 2019 for conditional compilation symbols for multi platform project with shared project not working 1 day ago 0 replies 26 views Myra - UI Library for the MonoGame.
The MonoGame Pipeline Tool provides an easy-to-use environment for converting content files into .xnb files for use in CocosSharp and MonoGame applications. For information on content pipelines and why they are useful in game development, see this introduction on content pipelines
This walkthrough will cover the following:
- Installing the MonoGame Pipeline Tool
- Creating a CocosSharp project
- Creating a content project
- Processing files in the MonoGame Pipeline Tool
- Using files at runtime
This walkthrough uses a CocosSharp project to demonstrate how .xnb files can be loaded and used in an application. Users of MonoGame will also be able to reference this walkthrough as CocosSharp and MonoGame both use the same .xnb content files.
The finished app will display a single sprite displaying a texture from a .xnb file and a single label displaying a sprite font from an .xnb file:
MonoGame Pipeline Tool discussion
The MonoGame Pipeline Tool is available on Windows, OS X, and Linux. This walkthrough will run the tool on Windows, but it can be followed along on Mac and Linux as well. For information on getting the tool set up on Max or Linux, see this page.
The MonoGame Pipeline Tool is able to create content for iOS applications even when run on Windows, so developers using Xamarin Mac Agent will be able to continue developing on Windows.
Installing the MonoGame Pipeline Tool
We will begin by installing the MonoGame, which includes the MonoGame Content Pipeline. Note that the MonoGame Content Pipeline is a separate download for Mac. All MonoGame installers can be found on the MonoGame Downloads page. We’ll download MonoGame for Visual Studio, but once installed the developer can use MonoGame in Visual Studio for Mac too:
Once downloaded, we’ll run through the installer and accept the defaults options. After the installer finishes, the MonoGame Pipeline Tool is installed, and can be found in the Start menu search:
Launch the MonoGame Pipeline Tool:
Once the MonoGame Pipeline Tool is running, we can start to make our game and content projects.
Creating an empty CocosSharp project
The next step is to create a CocosSharp project. It’s important that we create the CocosSharp project first so that we can save our content project in the folder structure created by the CocosSharp project. To understand the structure of a CocosSharp project, take a look at the BouncingGame, which will be using in this guide. However, if you have an existing CocosSharp project that you’d like to add content to, feel free to use that project instead of BouncingGame.
Once the project has been created, we'll run it to verify that it builds and that we have everything set up properly:
Creating a content project
Now that we have a game project, we can create a MonoGame Pipeline project. To do this, in the MonoGame Pipeline Tool select File>New.. and navigate to your project's Content folder. For Android, the folder is located at [project root]BouncingGame.AndroidAssetsContent. For iOS, the folder is located at [project root]BouncingGame.iOSContent.
Change the File name to ContentProject and click the Save button:
Once the project is created, the MonoGame Pipeline Tool will display information about the project when the root ContentProject item is selected:
Let’s look at some of the most important options for the content project.
Output folder
This is the folder (relative to the content project itself) where the output .xnb files will be saved. To keep things simple, we’ll use the same folder to hold our input and output files. In other words we’ll change the Output Folder to be . :
Platform
This defines the target platform for the content. Notice that this is Windows by default, so we’ll want to change this to our target platform which is Android (or iOS if following along with an iOS project).
Processing files in the MonoGame Pipeline Tool
Next, we’ll be adding content to our ContentProject. For this project, we’ll be adding files to the root of the project, but larger projects will typically organize their content in folders.
We’ll add two files to our project:
- A .png file which will be used to draw a sprite. This file can downloaded here.
- A .spritefont file which will be used to draw text on screen. The Content Pipeline Tool supports creating new .spritefont files, so there is no file to download.
Adding a .png file
To add a .png file to the project, we’ll first copy it to the same directory as the pipeline project, which has the .mgcb extension.
Next, we’ll add the file to the pipeline project. To do this in the MonoGame Pipeline Tool, select Edit>Add Item.., select the ball.png file and click Open. The file will now be part of the content project and, when selected, will display its properties:
We’ll being leaving all the values at their defaults as no changes are required to load the .xnb file in CocosSharp. We can build the file by selecting the Build>Build menu option, which will start a build and display output about the build. We can verify that the build worked correctly by checking the Content folder for a new ball.xnb file:
Adding a .spritefont file
We can create .spritefont file through the MonoGame Pipeline Tool. CocosSharp requires fonts to be in a Fonts folder, and CocosSharp templates automatically create a Fonts folder automatically. We can add this folder to the MonoGame Pipeline Tool by selecting Edit>Add>Existing Folder... Browse to the Content folder and select the Fonts folder and click OK:
To add a new .sprintefont file, right-click on the Fonts folder and select Add>New Item.., select the SpriteFont Description option, enter the name arial-36, and click Ok. CocosSharp requires very specific naming of font files – they must be in the format of [FontType]-[FontSize]. If a font does not match this naming format it will not be loaded by CocosSharp at runtime.
The .spritefont file is actually an XML file which can be edited in any text editor, including Visual Studio for Mac. The most common variables edited in a .spritefont file are the
FontName
and Size
property:We’ll open the file in any text editor. As our arial-36.spritefont name suggests, we’ll leave the
FontName
as Arial
but change the Size
value to 36
:Using files at runtime
The .xnb files are now built and ready to be used in our project. We’ll be adding the files to Visual Studio for Mac then we’ll add code to our
GameScene.cs
file to load these files and display them.Adding .xnb files to Visual Studio for Mac
First we’ll add the files to our project. In Visual Studio for Mac, we’ll expand the BouncingGame.Android project, expand the Assets folder, right-click on the Content folder, and select Add>Add Files.. First, we’ll select the ball.xnb we built earlier and click Open. Then repeat the above steps, but add the arial-36.xnb file. We’ll select the Keep the file in its current subdirectory option if Visual Studio for Mac asks how to add the file. Once finished both files should be part of our project:
Adding GameScene.cs
We’ll create a class called
GameScene,
which will contain our sprite and text objects. To do this, right-click on the BouncingGame (not BouncingGame.Android) project and select Add>New File... Select the General category, select the Empty Class option, and then enter the name GameScene.Once created, we’ll modify the
GameScene.cs
file to contain the following code:We won’t be discussing the code above since working with CocosSharp visual objects like CCSprite and CCLabelTtf is covered in the BouncingGame guide.
We also need to add code to load our newly-created
GameScene
. To do this we’ll open the GameAppDelegate.cs
file (which is located in the BouncingGame PCL) and modify the ApplicationDidFinishLaunching
method so it looks like:When running, our game will look like:
Summary
This walkthrough showed how to use the MonoGame Pipeline Tool to create .xnb files from an input .png file as well as how to create a new .xnb file from a newly-created .sprintefont file. It also discussed how to structure CocosSharp projects to use .xnb files and how to load these files at runtime.
Related links
-->This multi-part walkthrough shows how to create a simple 2D application using MonoGame. It covers common game programming concepts, such as graphics, input, game entities, and physics.
This article describes MonoGame API technology for making cross-platform games. For a full list of platforms, see the MonoGame website. This tutorial will use C# for code samples, although MonoGame is fully functional with F# as well.
MonoGame is a cross-platform, hardware accelerated API providing graphics, audio, game state management, input, and a content pipeline for importing assets. Unlike most game engines, MonoGame does not provide or impose any pattern or project structure. While this means that developers are free to organize their code as they like, it also means that a bit of setup code is needed when first starting a new project.
The first section of this walkthrough focuses on setting up an empty project. The last section covers writing all of our game logic and content – most of which will be cross platform.
By the end of this walkthrough, we will have created a simple game where the player can control an animated character with touch input. Although this is not technically a full game (since it has no win or lose conditions), it demonstrates numerous game development concepts and can be used as the foundation for many types of games. D link dwl g122 drivers for mac.
The following shows the result of this walkthrough:
MonoGame and XNA
The MonoGame library is intended to mimic Microsoft’s XNA library in both syntax and functionality. All MonoGame objects exist under the Microsoft.Xna namespace – allowing most XNA code to be used in MonoGame with no modification.
Developers familiar with XNA will already be familiar with MonoGame’s syntax, and developers looking for additional information on working with MonoGame will be able to reference existing online XNA walkthroughs, API documentation, and discussions.