Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Parsing "Collection of Images" with json doesn't work  (Read 1609 times)

0 Members and 1 Guest are viewing this topic.

Remi749

  • Newbie
  • *
  • Posts: 3
    • View Profile
Parsing "Collection of Images" with json doesn't work
« on: November 26, 2017, 04:53:54 pm »
Hi, so I have a Tiled map, I have a "based on a tileset image" tileset, and a "Collection of Images" tileset with a few images of different sizes inside.

Everything works fine, but not for the "Collection of Images" tileset and parsing this with json to our game.

Here is the layer loader from json to cpp. It loads the layer and it works fine, if I add something to the map from "Collection of Images" tileset, it is ignored. I can still collide with it, but it isn't shown.

void MapMaker::loadLayer(Json::Value &layer, std::list<Object *> &objects, TileSize tileSize) {

    MapLayer *tmp = new MapLayer(tileSize);

    tmp->width = layer["width"].asInt();
    tmp->height = layer["height"].asInt();

    memset(tmp->tileMap, 0, sizeof(tmp->tileMap));

    for(size_t i = 0; i < layer["data"].size(); ++i)
        tmp->tileMap[i] = layer["data"][(int)i].asInt();

    tmp->isCollisionLayer = layer["properties"]["Collision"].asBool();

    objects.push_back(tmp);

}

The crates in the images are from the "Collection of Images" tileset


but in-game these are gone, but the player can still collide with them...


I bet there is some code missing. if anyone can help that would be greatly appreciated.

I have attached the json map file if needed.
« Last Edit: November 26, 2017, 05:03:32 pm by Remi749 »

Kerachi

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: Parsing "Collection of Images" with json doesn't work
« Reply #1 on: November 26, 2017, 10:31:29 pm »
If you allow me I have some question about this.

  • Where do you load the texture (image(s))?
    • I see you loaded the width, height and set the collision, but I can't see where do you load the image.
    • I assume the "data" is the image in some kind of form, but still, how it will be an image?

    Maybe you should add to your code rows like:
Code: [Select]
imageName = layer["tiles"]["1"]["image"];
imageWidth = layer["tiles"]["1"]["imagewidth"];
imageHeight = layer["tiles"]["1"]["imageheight"];
//and other attributions...
//after that, you could load the image(s)...

  • I'm not sure what is tmp->tileMap, I mean it's probably an array or vector, but what is this? Can you explicate it for me, or show the code of MapLayer? Is it for storing the map(s)?

  • Where do you display (draw) the image(s)?

« Last Edit: November 26, 2017, 11:03:17 pm by Kerachi »

 

anything