05-09-2020, 06:30 PM
Hi!
Finally had time to check your post. Your "city.tmx" map doesn't contain any square object, is that right?
I've checked that Tilengine since release 2.5.0 can directly load "Rectangle" object type out of the box, for that purpose you can discard libtmx entirely:
Assuming you have an object layer named "collisions", this is how to load its objects:
The TLN_GetListObject() iterator is called in two different ways:
Finally had time to check your post. Your "city.tmx" map doesn't contain any square object, is that right?
I've checked that Tilengine since release 2.5.0 can directly load "Rectangle" object type out of the box, for that purpose you can discard libtmx entirely:
- Load the "object" layer with TLN_LoadObjectList() to get a TLN_ObjectList handler.
- Iterate the returned list with TLN_GetListObject() to get data about each object in a TLN_ObjectInfo struct.
Assuming you have an object layer named "collisions", this is how to load its objects:
Code:
TLN_ObjectList list = TLN_LoadObjectList("city.tmx", "collisions");
TLN_ObjectInfo info = { 0 };
bool has_object = TLN_GetListObject(list, &info);
while (has_object)
{
//do_whatever_with(info);
printf("Object %d, x=%d y=%d w=%d h=%d\n", info.id, info.x, info.y, info.width, info.height);
has_object = TLN_GetListObject(list, NULL);
}
The TLN_GetListObject() iterator is called in two different ways:
- First time, to get "first" object, the TLN_ObjectInfo pointer must ve a valid one
- Inside of the loop, to get "next" object, TLN_ObjectInfo must be NULL, meaining that it uses the previous one and that is a continuation.