I’m new with Monogame.Extended
I am trying to Load map .tmx file.
But i got this error.
Here is my content
And please you show me how to Draw Map from the .tmx file to screen.
here is my tmx file.
I’m new with Monogame.Extended
I am trying to Load map .tmx file.
But i got this error.
Here is my content
And please you show me how to Draw Map from the .tmx file to screen.
here is my tmx file.
@Tanakhon_Kaewkunha The exception Could not load ... asset as non-content file!
is fairly common pitfall for beginners. In my experience, it’s usually caused by an invalid file path. Could you post the complete exception details here by clicking on Copy exception details to the clipboard
in the popup window? It will have information of what exactly went wrong.
Thank you for reply.
Here is my error.
Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
HResult=-2146233088
Message=Could not load Map/purple_map asset as a non-content file!
Source=MonoGame.Framework
StackTrace:
at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action1 recordDisposableObject) at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) at MapTester.Game1..ctor() in C:\Users\Tkaewkunha\Source\Repos\Game1\MapTester\MapTester\Game1.cs:line 21 at MapTester.Program.Main() in C:\Users\Tkaewkunha\Source\Repos\Game1\MapTester\MapTester\Program.cs:line 17 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: HResult=-2146233088 Message=Could not load Map/Game/roguelike-pack/Spritesheet/roguelikeSheet_transparent asset as a non-content file! Source=MonoGame.Framework StackTrace: at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action
1 recordDisposableObject)
at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
at MonoGame.Extended.Maps.Tiled.TiledMapReader.Read(ContentReader reader, TiledMap existingInstance)
at Microsoft.Xna.Framework.Content.ContentTypeReader1.Read(ContentReader input, Object existingInstance) at Microsoft.Xna.Framework.Content.ContentReader.InnerReadObject[T](T existingInstance) at Microsoft.Xna.Framework.Content.ContentReader.ReadObject[T](T existingInstance) at Microsoft.Xna.Framework.Content.ContentReader.ReadObject[T]() at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]() at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action
1 recordDisposableObject)
InnerException:
HResult=-2146233088
Message=The directory was not found.
Source=MonoGame.Framework
StackTrace:
at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
InnerException:
HResult=-2147024893
Message=Could not find a part of the path ‘C:\Users\Tkaewkunha\Source\Repos\Game1\MapTester\MapTester\bin\Windows\x86\Debug\Content\Map\Game\roguelike-pack\Spritesheet\roguelikeSheet_transparent.xnb’.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
InnerException:
There it is, the problem.
Sorry ,but i have no idea how to fix it.
Can you suggest me.
Look if the path exists and the xnb file is properly compiled.
@Tanakhon_Kaewkunha The TiledMapReader
class is trying to load extra assets when you load a TiledMap
. If any of those assets don’t exist, loading the TiledMap
fails as well. What does your .tmx
look like?
here is my .tmx
@Tanakhon_Kaewkunha Yeah, you have a tileset with image source: Game/roguelike-pack/Spritesheet/roguelikeSheet_transparent.png
. When you load the map using the content pipeline, the TiledMapReader
will try to load the corresponding texture from the contents directory: Game/roguelike-pack/Spritesheet/roguelikeSheet_transparent.xnb
. It failed because it can’t find it. Did you build your Tiled map with the content pipeline correctly? Did you also build the tile sets as textures? You can check out this tutorial for getting started with building assets with the content pipeline in MonoGame. You can also take reference of the .mgcb
file for the Tiled maps demo.
@LithiumToast
I’m already build it.
and here is my Content.mgcb
My content.mgcb data
has
begin Map/purple_map.tmx
/importer:TiledMapImporter
/processor:TiledMapProcessor
/build:Map/purple_map.tmx
it look like
begin level01.tmx
/importer:TiledMapImporter
/processor:TiledMapProcessor
/build:level01.tmx
in Tiled maps demo
And i have stupid question.
Why i need Game/roguelike-pack/Spritesheet/roguelikeSheet_transparent.xnb?
Btw, when i click on rebuilt
it showing this.
Thank you for reply.
Because your .tmx
has a tileset with an image source Game/roguelike-pack/Spritesheet/roguelikeSheet_transparent.png
. You can see this if you open up the .tmx
file using a regular text editor (the contents are in XML). When the map is loaded in game, the TiledMapReader
will try to load the tileset image (as a Texture2D
) for each tileset. The original problem you have is that tileset asset does not exist at the expected path Map\Game\roguelike-pack\Spritesheet\roguelikeSheet_transparent.xnb
. (Content\
is the default root directory for the assets).
Could you tell me how do i find my roguelikeSheet_transparent.xnb and how to add it to Map/Game
After build it , i can’t see any sub directory in Map/Game
Expected asset with full path: C:\Users\Tkaewkunha\Source\Repos\Game1\MapTester\MapTester\bin\Windows\x86\Debug\Content\Map\Game\roguelike-pack\Spritesheet\roguelikeSheet_transparent.xnb
Content path:
C:\Users\Tkaewkunha\Source\Repos\Game1\MapTester\MapTester\bin\Windows\x86\Debug\Content
Asset path with .xnb
extension:
Map\Game\roguelike-pack\Spritesheet\roguelikeSheet_transparent.xnb
Asset path without .xnb
extension:
Map\Game\roguelike-pack\Spritesheet\roguelikeSheet_transparent
You need to build the tileset image as a Texture2D
and have it sit in the correct path Map\Game\roguelike-pack\Spritesheet\roguelikeSheet_transparent
for the problem to be resolved. Just for demonstration, If everything is okay you should be able to load the Texture2D
manually like so
Content.Load<Texture2D>("Map\Game\roguelike-pack\Spritesheet\roguelikeSheet_transparent");
The above snippet is exactly what happens behind the scenes automatically for every tileset when you call
Content.Load<TiledMap>("Map\purple_map");
Thank you ,i’ll try it.
Thank you… @LithiumToast
Now i can load my map !!!.
I have to add png souce file to my Content.
lik this
Can I just say tl;dr
Make sure you load the image along with the map file in the content pipeline.
This tripped me up when I was playing around with a test map. You don’t actually have to make a call to content.Load(“mysprite”) (unless you need this texture in your game like displaying on a screen). If you’re just loading a .tmx file you just need to add it to the .mgcb file. It’ll get compiled and the .xnb file will get copied to your output directory, then when the .tmx loader does its thing, it’ll look for an asset and try to load it. Maybe that’s what @lozzajp was saying so apologies if I’m saying the same thing, just wanted to make it clear you don’t need code for all map tilesets.