Difference between revisions of "Generating and using XNB files"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(completion)
(Note)
 
(17 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
 
==Visual Studio==
 
==Visual Studio==
I don't have any experience with using xamarin or mono studio, hence I assume they have different ways to add files to your project; for visual studio, if you have Monogame installed, the Windows Monogame Content Pipeline is automatically installed for each project you create. If you do not see the content pipeline check with the wiki admin or message my user acount for assistance (User:M0hk4l3). In the following few paragraphs I'll introduce you to how one can use the Content pipeline.
+
I don't have any experience with using xamarin or mono studio, hence I assume they have different ways to add files to your project; for visual studio, if you have Monogame installed, the Windows Monogame Content Pipeline is automatically installed for each project you create.  
  
# Firstly you should create a new project:
+
==Open The Content Builder==
## Goto File\New\Project and then select a new project. [[File:MonogameNP.PNG]]
+
You need to have a working MonoGame project to use.
# Then open the Content Pipeline [[File:NavExpContent.PNG|200px|right]]
 
## Navigate to the solution Explorer.
 
## Expand the content folder.
 
## double click on the Content.MGCB file.
 
# You should be able to see your project content [[Media:ContPipe.PNG]]
 
## From the pipeline you can modify existing files, add existing files or create new files to your project.
 
  
 +
Make sure you have solution explorer selected, and then open the Content Pipeline:
  
 +
[[File:NavExpContent.PNG|200px]]
  
* To add an existing file (for example test.png [an image file])
+
You can double click on the Content.MGCB file, if this brings up a text file you need instead to right click and choose open with. the MonoGame Pipeline Tool should be listed.
** Select your Content directory, navigate to "edit\add\existing item"
+
** In the popup menu navigate to the file you wish to add, then select and add it.
+
You should be able to see your project content  
** In the add file dialog box you have 3 options on how to store the file (this is pretty self explainatory, hence I wont go into detail on it), if you are unaware of what to do then just select "Copy the file to the directory".
 
* To delete an existing file in your Content
 
** Select the file in question
 
** Right click on the selected file
 
** Click delete (Note if you delete a file you'll later use in your project, an Exception will be thrown if a file with the same name is not in the content pipline).
 
* To create a new file, such as a spritefont (which can be used to print text in your game)
 
** Select your Content directory, navigate to "edit\add\new item"
 
** Select the content type: Effect, Sprite Effect, SpriteFont Discription, XML Content
 
** Enter a name for your new file & click OK to add it to your content pipeline.
 
** Note if you want you can modify newly created files by double clicking on them from the pipeline.
 
* Just as a final note, if you grow tired of having every project file in the main directory, you can create folders and place files within them.
 
** To create folder goto "Edit\Add\New Folder"
 
  
 +
[[File:ContPipe.PNG|400px]]
  
 +
From the pipeline you can modify existing files, add existing files or create new files to your project.
  
 +
==Add Existing Item==
  
S.N. For those you having difficulty loading files added to the pipeline into your game, remember that file types are removed after the files are added to the pipeline. Hence if you added a file name "X.png" into the folder "Blarg\Path\To\Folder" you can load it into your game by writing Content.Load<Texture2D>("Blarg\Path\To\Folder\X"); note no file type.
+
To add an existing file (for example test.png):
 +
 
 +
* Select your Content directory, navigate to "edit\add\existing item"
 +
* In the popup menu navigate to the file you wish to add, then select and add it.
 +
* In the add file dialog box you have 3 options on how to store the file, just select "Copy the file to the directory".
 +
 
 +
==Delete an item==
 +
To delete an existing file in your Content
 +
* Select the file in question
 +
* Right click on the selected file
 +
* Click delete (Note if you delete a file you'll later use in your project, an Exception will be thrown if a file with the same name is not in the content pipeline).
 +
 
 +
==Create a New File==
 +
To create a new file, such as a spritefont (which can be used to print text in your game)
 +
* Select your Content directory, navigate to "edit\add\new item"
 +
* Select the content type: Effect, Sprite Effect, SpriteFont Description, XML Content
 +
* Enter a name for your new file & click OK to add it to your content pipeline.
 +
* Note if you want you can modify newly created files by double clicking on them from the pipeline.
 +
 
 +
==Notes==
 +
Remember to click 'Build' or 'Rebuild' after you have added something to the pipeline. You can also right click on an item, and rebuild just this item.
 +
 
 +
For those you having difficulty loading files added to the pipeline into your game, remember that file types are removed after the files are added to the pipeline. Hence if you added a file name "X.png" into the folder "Blarg\Path\To\Folder" you can load it into your game by writing Content.Load<Texture2D>("Blarg\Path\To\Folder\X"); note no file type.
 +
 
 +
Just as a final note, if you grow tired of having every project file in the main directory, you can create folders and place files within them. To create folder goto "Edit\Add\New Folder"

Latest revision as of 07:56, 31 January 2019

Usage

XNB files are the content files stored by the monogame API (& by extension the Microsoft XNA fraework). Monogame requires you stors any files you may use in the project, in the form of an xnb file; note because all files used by the monogame framework have a .XNB file extension you cant have two files with the same given name (within the same directory).

Visual Studio

I don't have any experience with using xamarin or mono studio, hence I assume they have different ways to add files to your project; for visual studio, if you have Monogame installed, the Windows Monogame Content Pipeline is automatically installed for each project you create.

Open The Content Builder

You need to have a working MonoGame project to use.

Make sure you have solution explorer selected, and then open the Content Pipeline:

NavExpContent.PNG

You can double click on the Content.MGCB file, if this brings up a text file you need instead to right click and choose open with. the MonoGame Pipeline Tool should be listed.

You should be able to see your project content

ContPipe.PNG

From the pipeline you can modify existing files, add existing files or create new files to your project.

Add Existing Item

To add an existing file (for example test.png):

  • Select your Content directory, navigate to "edit\add\existing item"
  • In the popup menu navigate to the file you wish to add, then select and add it.
  • In the add file dialog box you have 3 options on how to store the file, just select "Copy the file to the directory".

Delete an item

To delete an existing file in your Content

  • Select the file in question
  • Right click on the selected file
  • Click delete (Note if you delete a file you'll later use in your project, an Exception will be thrown if a file with the same name is not in the content pipeline).

Create a New File

To create a new file, such as a spritefont (which can be used to print text in your game)

  • Select your Content directory, navigate to "edit\add\new item"
  • Select the content type: Effect, Sprite Effect, SpriteFont Description, XML Content
  • Enter a name for your new file & click OK to add it to your content pipeline.
  • Note if you want you can modify newly created files by double clicking on them from the pipeline.

Notes

Remember to click 'Build' or 'Rebuild' after you have added something to the pipeline. You can also right click on an item, and rebuild just this item.

For those you having difficulty loading files added to the pipeline into your game, remember that file types are removed after the files are added to the pipeline. Hence if you added a file name "X.png" into the folder "Blarg\Path\To\Folder" you can load it into your game by writing Content.Load<Texture2D>("Blarg\Path\To\Folder\X"); note no file type.

Just as a final note, if you grow tired of having every project file in the main directory, you can create folders and place files within them. To create folder goto "Edit\Add\New Folder"