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
Related
I have problem when publishing a Visual Studio 2017, C#, ASP.Net MVC 5 project. I do publish with following settings :
Problem with the CSS content link, for example bootstrap :
#font-face{font-family:'Glyphicons Halflings';src:url(../fonts/glyphicons-halflings-regular.eot);
If the bootstrap.min.css located in localhost/bower_components/css/bootstraps/bootstrap.min.css, that css will displayed as localhost/fonts/glyphicons-halflings-regular.eot at client.
If I just copy paste all project without publish it to the server, the link will displayed correctly as localhost/bower_components/css/fonts/glyphicons-halflings-regular.eot
This is happens for all css including images and other file in css.
With what is available of code knowledge in your question and what shown and explained. I can see in your code your relative path has the issue.
You are using ../ change it to ./ or ~/. That should fix the issue.
By using ../ you are stepping the css path over.
In the {YourProjectName}\App_Start\BundleConfig.Cs
Add Instance of CssRewriteUrlTransform Class when adding Bootstrap Bundle Like This:
public static void RegisterBundles(BundleCollection bundles)
{
StyleBundle bootCss = new StyleBundle("~/styles/bootstrap");
bootCss.Include("~/Content/bootstrap/styles/bootstrap.css",
new CssRewriteUrlTransform());
bootCss.Include("~/Content/bootstrap/styles/bootstrap-theme.min.css", new CssRewriteUrlTransform());
bundles.Add(bootCss);
}
Build action set to None by Default so you need to change it to Content.
Right click in affected file > properties > set Build Action to Content
I hope this can help
I found that some of my newly added files weren't publishing even though everything was set up correctly. I closed and reopened VS 2019 to find that the newly added files weren't added to the project. I remember a while ago the occasional need to go to File > Save All.
This is a simple solution, but hard to see when it's the issue.
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.
I have an big issue when publishing my application on another machine. The apps resources as pictures and sounds can't be found anywhere thou they actually are installed somewhere I really don't know where.. I'm talking about oneClick Deployment! I have put the files in separate folders in the Resource folder in the Solution explorer and the path is a string path inside Settings like this ....\Resources\Images\Cards\ and ....\Resources\Sounds\ Whatever I do the program can't find its resources so what is the basic issue here? I believe it's something wrong with the path because I see when the program gets installed it installs everything (same amount of MB). Any suggestions anybody?
C# Visual Studio 2010 Black Jack Game
I had the same problem, You can do the following:
Open the .resx file
Just above the file, there is a access modifier listbox. if it is set to "No code generated" , Select public from the list
Build,
Hopefully, problem solved.
Well I found the answer to this issue after a while of struggling..
You have to erase the "..\..\" before the Resource folder in the "settings" while you are about to publish otherwise the deployed application can not find its resources thus they will not be at the same folder as described. But remember if you want to continue working on your project you must put back "..\..\" for debugging the program otherwise debugging will not work!!! I was not allowed to publish the image to show you here because of I don't have earned "10" reputations yet.. :)
In Visual Studio 2010 professional open your project
open the project properties
select Web
Under Servers set the Virtual Path as your deployed website virtual path.
If you set the virtual path to /BookStore
You need to update all the resources references
Look like the following from
src="../../img/picture.png"
to
src="/BookStore/./img/picture.png"
I had the same issue, I assume it is suppose to be that way with two different paths.
This is what I did so I no longer had to edit the file paths when going from debugging to production.
Public RP As String = IO.Path.GetFullPath(My.Resources.ResourceManager.BaseName)
Public filePath As String = RunOrInstall(RP)
'Checks to see if debugging or installed and returns correct path
Private Function RunOrInstall(RP)
Dim pathing As String
If RP.ToString().IndexOf("bin") = -1 Then
pathing = RP.Substring(0, RP.LastIndexOf("\")) & "\Resources\"
Else
pathing = RP.Substring(0, RP.LastIndexOf("bin")) & "Resources\"
End If
Return pathing
End Function
If I understand the problem correctly, I believe I had a similar issue...
I was creating an installer for one of my c# apps, and whenever I installed the program it couldn't find any of the resources it needed to run.
The problem ended up being that the files that the installer was putting on the desktop and in the programs menu weren't set to "shortcut". Try setting "Type" to "Shortcut" (I'm using microsoft visual studio 2008, and it requires a right-click -> create new shortcut -> select file to create a shortcut to... it may be different for whatever IDE you're using)
edit - I just noticed you put vs 2010 in your tag, so the process should be very similar
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");
I have a WPF assembly in which I would like to embed five icons for different filetypes associated with my application.
How can I embed these icons into my EXE?
#smoore #Groky #ChrisF, thank you.
Unfortunately, this is not what I asked. I see that my question was quite vague 0_°. Let me rephrase the question:
I have icons, say Application.ico, Document.ico, etc. as resources in my WPF projects. I access these icons in most cases with the following:
<Image Source="/MyAssembly;component/Resources/Icons/Application.ico" />
That works every single time. I know that.
What my question is about is how can I use the same icons from Windows Explorer for file associations in the registry. I want to be able to access the icons with a path like:
C:\Program Files\MyApp\MyApp.exe,1
Like in how icons are associated with filetypes in HKEY_CLASSES_ROOT.
AFAIK, I should use a resource file (.rc), compile and merge it with my EXE. Something along the lines of:
101 RT_ICON Application.ico
102 RT_ICON Document.ico
// etc...
Is this the right way in WPF? Is there an alternative, especially since this method seems to lead to the erasure of the assembly version from my AssemblyInfo.cs. I am still prepared to have to write the versioning info in the resource instead of the assembly's info.
I have found one solution! It's not perfect but it does what I want! As I used very long Scandinavian nights to find the solution, I feel that I have to share it here.
Here's what I did:
1) Wrote a dumb console C# app.
class ResTest {
static void Main() {
System.Console.WriteLine("Hello World!");
}
}
2) Did a simple csc restest.cs to test that my code worked.
3) Opened Notepad and wrote the following in a file I dubbed App.rc.
101 ICON "Application.ico"
102 ICON "Document.ico"
103 ICON "Help.ico"
4) Ran rc /v App.rc, the Resource Compiler. A new file, App.res had appeared.
5) Reran csc but this time:
csc /win32res:App.res restest.cs
6) restest.exe had now the icon with the ID of 101 and I could find the two other icons in Axialis IconWorkshop.
Now, I noticed that my assembly information (version, product name, blah blah blah) had disappeared. I googled VS_VERSION_INFO and came about MSDN's article about the VERSIONINFO structure which in RC files defines the attributes I need.
I would have preferred a more 'automated' method, but I must do what I can using the C# Express and the Windows Vista SDK.
-- Hope that you can use this...
Create App.rc:
101 ICON "Application.ico"
102 ICON "Document.ico"
103 ICON "Help.ico"
Compile:
rc App.rc
Add App.res to your project (leave None as your Build Action).
Build.
All done!
I've just created a simple tool to do exactly this without having to mess with .res files. (If you manage your own .res files you won't get a manifest and version resource created automatically). It is a tiny utility which you can use as part of your Post-Build event and lets you add all icon files in a particular folder to your assembly. If we assume that you have a icons folder under your main project folder you can add the following post-build event:
C:\path\to\InsertIcons.exe $(TargetPath) $(ProjectDir)icons
A further description and a download can be found at http://einaregilsson.com/add-multiple-icons-to-a-dotnet-application/
Project Properties -> Resources -> Add Resource -> Add New Icon/Add Existing File (depending on whether or not you've already made the icon)
In addition to adding the files to your project resources, you can add the files to your project and set their Build Action to resource.
You can then refer to the files from XAML using the Source property. For example a file Icon.png in a directory "Resources" would be loaded using:
<Image Source="/Resources/Icon.png"/>
And to load the file from code you would use:
new BitmapImage(new Uri(#"pack://application:,,,/Resources/Icon.png"))