• XNA 4.0 Map loading help.
    14 replies, posted
  • So I'm trying to make something that will read a picture, and generate a map based on pixel color (Or a number string if that works better). What code would I use to have it place a certain material based on that? Say for example, if the pixel is blue, generate a stone "block." I'm trying to make a map system similar to that of Dungeon Keeper 2 by Bullfrog. It's 3D, and the map is in a grid-like fashion. I haven't found any tutorials that teach something like this. Thank you in advance for your input.
  • [url]http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx[/url]
  • Thank you for the link, hopefully it's 4.0 compatible, I've found a lot of the stuff on there isn't.
  • Avatar of Hack
  • [QUOTE=ArchColossus;34761960]So I'm trying to make something that will read a picture, and generate a map based on pixel color (Or a number string if that works better). What code would I use to have it place a certain material based on that? Say for example, if the pixel is blue, generate a stone "block." I'm trying to make a map system similar to that of Dungeon Keeper 2 by Bullfrog. It's 3D, and the map is in a grid-like fashion. I haven't found any tutorials that teach something like this. Thank you in advance for your input.[/QUOTE] Your map loading would take much longer because of that method call to check each individual pixel. I personally recommend having a XML File with all the blocks inside, the loading times will decrease substantially. Up to you though.
  • Avatar of dajoh
  • [QUOTE=Hack;34773711]Your map loading would take much longer because of that method call to check each individual pixel. I personally recommend having a XML File with all the blocks inside, the loading times will decrease substantially. Up to you though.[/QUOTE] XML is definitely going to be slower to load from compared to an image where each pixel is a block.
  • Avatar of Ybbats
  • The best way to do this would probably extend the content pipeline for image objects so you could just use Content.Load<Map>() to load your maps.
  • So that link shows how to get the pixel's color, how do I tell that to place a certain model into a grid? I know that there are going to be if statements involved, but I haven't coded anything like this yet.
  • Avatar of geel9
  • You make the grid yourself. You say "if r == x && g == y && b == z" or, even better, use some sort of hashmap/dictionary.
  • I've only been coding in XNA for about 2 months, I'm not familiar with what a hashmap is, or the context for dictionary. '~' Everything I know is from RB Whitaker, Riemers, and Aaron Reed's XNA book. I've found that there's not much that teaches past this point. Thank you for the suggestion, but could you elaborate a bit more?
  • Thank you for the link, I actually managed to forget I could just look that up. Whoops. Anyway, how do I set one of these up in XNA? And how do I make sure it loads correctly?
  • I can't find the code to tell the game 1, what to place based on color, and 2, where to place it in the grid based on the pixels location. Anyone know how these work?
  • Avatar of Richy19
  • [QUOTE=Topgamer7;34813799][URL="http://en.wikipedia.org/wiki/Hash_table"]Hashmap[/URL][/QUOTE] Isnt a hashmap just a C# dictionary?