My code is
new GameFont(Content.Load<SpriteFont>("LoadingFont"), "LoadingFont")
According to what I've read, you have to use VS2010 to compile your assets into .xnb format, which I have done, and place them into the Content subfolder in your bin directory, which I have also done. However, I get an error saying "Could not load LoadingFont asset!".
I'm not really sure what else to do. I read a very old post saying that assets made using XNA 4 won't work, but I don't know if that's still true, or how to change my version of XNA to 3.1.
Any ideas? Perhaps there's a better way without using VS2010 at all?
Have you added the content to the Content folder of your project and set the Build Action to Content (in the properties window).
I'm not exactly sure what the process is to use assets in the .xnb format. I know it can be done that way but I normally just add the raw image and sounds files to my Content folder directly. Font's might be a little trickier to do that way though.
EDIT: 2015
A lot of things have changed since this question was written. These days MonoGame has it's own Pipeline tool for processing content into XNB files. The first thing to try would be to process your SpriteFont using the new Pipeline. This way you can avoid the need to depend on XNA altogether.
Alternately, another way to get around font issues in MonoGame is to pre-render them to a texture using the BMFont tool and use MonoGame.Extended to render them in your game.
Once you've installed MonoGame.Extended you can load fonts created with BMFont just as you would a SpriteFont but using the BitmapFont class instead.
_bitmapFont = Content.Load<BitmapFont>("my-font");
Then render some text like so:
_spriteBatch.Begin();
_spriteBatch.DrawString(_bitmapFont, "Hello World", new Vector2(100, 200), Color.Red);
_spriteBatch.End();
I have a full tutorial on my blog
I've been using MonoGame in VS2012 with no trouble; Content.Load<T>("myContent") still works for me. One thing that has been catching me out lately (tip: don't code when sleep-deprived) is that you have to check your assets are set to "Copy to output directory" in Solution Explorer, or else when the game builds, the assets won't go with it, which is why you get that error - it can't load what isn't there! Right-click on your assets and look under Properties. If they're set to "Do not copy" then you'll want to change that.
Like #craftworkgames I can't give you a full answer. But the traditional Content Pipeline that came with XNA 3.1 has gone in 4. So any assets need loading a slightly different way. For example, to load a .png asset to display a sprite I do the following:
rock = Texture2D.FromStream(GraphicsDevice, TitleContainer.OpenStream(#"Rock-Large-Stones-PT.png"));
and add the .png file to the solution as normal. I'm pretty sure it's going to be something similar for fonts but I haven't quite figured it out yet either ;)
I was having the same issue not sure if you got it resolved or not but here is what I did.
Click on the Monogame Content Pipeline under the "Content" folder.
Add in your spritefont or texture.
Make sure in the Monogame Content Pipeline that you change the action from "Build" to "Copy"
Then when you want to load the content simply;
texture = content.Load("texture.png");
Hope this helps :)
I had similar problem but with 'Windows 8 Store' as a target platform... while everything was fine with Windows Open GL version.
On Windows 8 I received "could not load as a non-content file" when I tried content.Load("Fonts/TestFont").
I replaced MonoGame DLLs in my solution with the MonoGame.Windows8 project (I downloaded the sources from CodePlex) and I did some debugging... and found out that MonoGame looks for the Content folder in the bin...\Debug\AppX folder... while during the build the Content folder is copied into different place. So when I manually copied the Content folder into AppX folder, the error has gone and my game prototype works fine now.
I guess I either missed some setting in the Project preferences related to AppX (Presumably this folder is needed for the Windows 8 device emulator?) or... MonoGame should look for the Content folder in different place... Anyway I will be renewing the Content folder manually for now because it is copied into wrong place during the compilation.
I have Content folder in my project and build action is set correctly (Content)... and 'Copy always' is chosen but during the build (compliation) that Content folder is copied to Debug folder while it should be copied to Debug\AppX folder otherwise MonoGame can't find it.
(I maybe wrong with exact paths because I am currently at work and the issue is at my home PC)
Maybe it is just some configuration issue in my Visual Studio 2012.
Hope this information helps.
Related
I had some unusual errors on a relatively small Unity project with six c# scripts written in Visual Studio. It was all working fine, and I came back to it after the weekend. Upon opening, there were 18 new errors which were preventing the code from compiling and I spent several hours trying to figure out what was going on.
The main errors were saying things like Type or namespace name 'GUIColorOverride' could not be found and associated script cannot be loaded, assign a valid script, even though they were linked and I could see the scripts had no errors in Visual Studio. I even did a full Unity uninstall and rebooted, then a clean install. This didn't fix it.
I tried a number of other things such as backing up the scripts from the assets folder and then deleting them. Opening the project and pasting them back in as 'clean' new scripts. This didn't work. I am using Unity's Cloud Collab so was even able to use this to go back to earlier pushes of the project (which had all worked). Nope.
Solved it! The issue was that the local Projects folder I had been using was connected to Google Backup and Sync. This messed with some of the files in some of the folders in PackageCache in Particular in the MyProject > Library > PackageCache > com.unity.timeline#1.2.13 > Editor > directory.
[FIX] To fix and prevent this from happening in future, I turned off Google Backup and Sync for my Unity Project(s), and am now exclusively using Unity Collab and Git. Using the specific errors that were showing in the Unity console, I located the exact path of the Unity-created files that were causing these errors in my broken project, and replaced them with the same files from a working project. This fixed all of the errors. There must have been some corrupted or partially synced files in these folders which caused Unity to have a tantrum. Hope that helps someone!
You should exclude these from the Backup!
Basically you can exclude anything that would also be excluded from git via e.g. this "official" .gitignore file for Unity projects.
Any file and folder listed here will be regenerated by Unity automatically and should not appear in any version control / Backup.
The entire Library folder in particular is part of it since its content changes quite rapidly and is recompiled every time you change a script, install/remove a package etc.
Checkout Unity Manual - Behind the Scenes for more information in detail
When backing up a project, or adding a project to a Version Control Repository, you should include the main Unity project folder, containing both the Assets
and ProjectSettings folders. All the information in these folders is crucial to the way Unity works. You should omit the Library and Temp folders for backup purposes.
To solve an already present issue with the Library folder you can most of the times fix it by simply closing Unity, deleting the entire Library folder via your file browser and opnening Unity again → Unity will rebuild the Library
No code, since it's not a code problem, rather a visual studio one.
I've searched this problem up a bit and found people saying they had this problem, not really specifying how they got it, and most people answering "you should set AndroidManifest.xml's build actions to none" without any explanation of why this would work, which, well won't work for me since it's already what I have and I'm getting the error anyway.
How I came to have this problem:
I made a few files, file1, file2, file3, in my assets directory.
I would then read them with a streamreader. This worked.
Fast forward a few weeks, I decide to rename them, through visual studio, to file1.txt, file2.txt ... etc.
When I compiled/launched it on my device, it did not work. An exception on streamreader told me the file wasn't found. And before that I had 3 errors "#(Content)build action is not supported" for each of my files.
I assume the problem lies in the build actions or possibly the way android behaves with some specific files? Either way how could this have changed by changing the file format? I made them .txt files for clarity purposes, I didn't expect everything to break down after that.
Ontop of that, I could not revert it. I removed the file extensions, and I still have the same problem now.
What should I do to have my files in the assets folder properly deployed on my machine just like they used to ? Is it related to the build options?
Thanks in advance.
As highlighted by Jason in the comments above, the build actions for android assets should be AndroidAsset, which got changed after I renamed them. This menu can be found on the properties of the file.
https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/resources-in-android/android-assets?tabs=windows
When trying to import an image into my 'game' I get a error message. The one displayed in the title. it is called content1.png and is in the Content folder. I have
public override void LoadContent()
{
base.LoadContent();
path = "Content/content1.png";
splash1 = content.Load<Texture2D>(path);
}
and it doesn't load it.
I have no idea what to do here.
It's seems like the content.Load<Texture2D> method tries to open the file from your File-System and it is not founded there, do the following to solve it:
In Visual Studio -> Right-Click on the content1.png file -> Select Properties ->
Set the Build-Action to "Content" in the properties window for
content1.png.
Set the Copy to Output Directory to -> Always
While the accepted solution didn't work for me, I finally figured out that it was the relative path of the asset that was creating problems, so changing
Content.Load<Texture2D>("Graphics\\MyAsset.png")
to
Content.Load<Texture2D>("..\\Graphics\\MyAsset.png")
did the trick for me.
In MonoGame 3.5.1 you must use MonoGame pipeline tool for your resources, and include builded *.mgcb file to your content folder in project. See sample project Platformer2d.
MonoGame pipeline tool
http://www.monogame.net/2016/03/17/monogame-3-5/
Samples https://github.com/MonoGame/MonoGame.Samples
I am trying to load a font into my game for iPhone. I am using C# and MonoTouch and the excellent MonoGame project (I have got the latest build from the develop3d branch on github).
My fonts load correctly on Windows but when I try to run the game on iPhone I get an error saying could not load font. I have loaded the sprite font into a MonoGame content project and compiled for iOS.
I have imported the produced xnb file in as content, set it to content mode in properties and marked it as copy if newer. However it still won't load. After a lot of digging I found that iOS does not support DXT compressed fonts which is apparently what a SpriteFont is.
I have no idea as to how to go about loading the font into my game. Can someone please help with some code as to how to do it?
I have just figured it out. For those who are struggling with the same thing follow these steps:
Create a new solution choose the mono game content for all platforms (which is basically a dummy game for building content)
Add a new mono game content builder project
Set the build type to the type you want e.g. iOS
Add the content you want
In the property window for each content file change the content processor, to the mono game version of the content you are building. e.g. for a texture choose "MonoGame - texture"
Build the solution which will build the content into a folder for the platform you have built for in the release directory
Add the content into your game project from the built folder of the content project. Make sure you set the build action to content and the copy to output directory to copy if newer (or copy always doesnt really matter)
Use the content using the normal content loader in xna
This is embarrassing. It is a file not found problem with my XNA + Silverlight project.
I'm modifying the "My Little Teapot" XNA + Silverlight sample for Windows Phone 7, at http://msdn.microsoft.com/en-us/library/ff431744%28v=vs.92%29.aspx and am getting a File Not Found error in OnNavigatedTo() when I merely try to load a texture:
myTex = content.Load("tex1");
(You'll notice this isn't the usual file not found question where the coder is trying to load "tex1.png" instead of "tex1".)
My solution has the same project as in the sample, "sdkMyLittleTeapotCS", and a content project I added, "my content". I added "tex1.png" to the "my content" project, and its asset name is indeed "tex1". Its build action is set to "Compile", and I've tried setting the "Copy to Output Directory" settings to "Do not copy" (which is what works in my normal XNA projects) and also to "Copy if newer".
In all cases I get an exception with a file not found. What is this idiot doing wrong? Thanks in advance!
Shouldn't the build action be set to Content instead of Compile?
Shouldn't your code read :
myTex = content.Load<Texture2D>("tex1");
Remove the offending texture from your content project but do not delete it from disk. Then, drag it from an Explorer window back to your content project and make sure the name remains "tex1" - this will force the content project to recreate the associations to the texture - which those associations appear to be bad in their current form.
Probably you have the tex1 file in a subfolder. In this case you must provide the full path:
myTex = content.Load<Texture2D>("foldername/tex1");