Hello again, Mono Comm,
First off, thanks for the help on my previous topic.
I don’t post a lot because I’m still learning and I’ve bumped into a GREAT learning experience that I can’t seem to find good beginner documentation for. Like the title lists, I’ve decided to use Tiled maps saved as JSON files. I’m testing a possible animation for my world map (the water) and I can export just fine from Tiled, open the file and it reminds me of XML in some ways, but now to my problem / question:
Is there any good beginner tutorial or help that I can find here to get this JSON file properly imported into my game? (problem 1:) When I “include” the file into my solution, it requires my ENTIRE file pathway in order to read it… that won’t work if someone were to play the game on their system, of course
Looks like this:
using (StreamReader reader = new StreamReader("C:/Users/Username/Desktop/DC Project/FP_RPG_V3_OPENGL/FP_RPG_V3_OPENGL/JSON/World Map TileSet.json"))
{
string json = reader.ReadToEnd();
var animationTiles = JsonConvert.DeserializeObject(json);
}
(Problem 2:) Once I have the test file in, I see all kinds of data.
Like this:
{ "columns":10,
"image":"DC Project\/FP_RPG_V3_OPENGL\/FP_RPG_V3_OPENGL\/Content\/World_Map\/World Map.png",
"imageheight":676,
"imagewidth":676,
"margin":0,
"name":"World Map TileSet",
"spacing":4,
"tilecount":100,
"tiledversion":"1.4.1",
"tileheight":64,
"tiles":[
{
"animation":[
{
"duration":200,
"tileid":14
},
{
"duration":300,
"tileid":26
},
{
"duration":400,
"tileid":29
},
{
"duration":600,
"tileid":36
}],
"id":14
}],
"tilewidth":64,
"transparentcolor":"#ffffff",
"type":"tileset",
"version":1.4
}
The next problem is… all I need is the animation tiles and durations, not so much the rest.
I’m just learning JSON and how to deserialize it but I clearly don’t know enough. Do I need to store ALL of that data or can I just grab what I need?
Once I have the file read, it attempts to store it in an object of MapTile type, but that class has other parms that aren’t in the JSON. Does that matter?
If I can figure out how to work this, I intend to load all world map data using this method, but for now I just want to test it out and get the feel of it. (LEARN DANIELSON!)
I’ve been all over the net (Here, Stackoverflow, C# Corner…etc) and it’s hard to make since of what is going on as they aren’t too clear for beginners. I’ve seen things like storing in a list, errors thrown for array issues, and the like. My map tiles are currently loaded into an array of MapTile[,] for the grid.
Is using a JSON a good approach? Am I on the right track?
If need be, I’ll post other code.
Thanks again for any help! Sorry if this isn’t too clear. I’m trying! Haha