Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getLayerAs error #75

Closed
1-max-1 opened this issue Sep 5, 2020 · 4 comments
Closed

getLayerAs error #75

1-max-1 opened this issue Sep 5, 2020 · 4 comments

Comments

@1-max-1
Copy link

1-max-1 commented Sep 5, 2020

Im using the example code from the quick start. On compile, I get an error:
error: undefined reference to 'tmx::ObjectGroup& tmx::Layer::getLayerAs<tmx::ObjectGroup>()'

Here's the code as a refresher:

		tmx::Map map;
		if(map.load("map1.tmx")) {
			const auto& layers = map.getLayers();
			for(const auto& layer : layers)
			{
				if(layer->getType() == tmx::Layer::Type::Object)
				{
					const auto& objectLayer = layer->getLayerAs<tmx::ObjectGroup>();
					const auto& objects = objectLayer.getObjects();
					for(const auto& object : objects)
					{
						//do stuff with object properties
					}
				}
				else if(layer->getType() == tmx::Layer::Type::Tile)
				{
					const auto& tileLayer = layer->getLayerAs<tmx::TileLayer>();
					//read out tile layer properties etc...
					SDL_Log("%s", tileLayer.getName().c_str());
				}
			}

			const auto& tilesets = map.getTilesets();
			for(const auto& tileset : tilesets)
			{
				//read out tile set properties, load textures etc...
			}
		}
@fallahn
Copy link
Owner

fallahn commented Sep 5, 2020

Are you making sure to include ObjectGroup.hpp in which the templated function is defined?

Which compiler/environment are you using? I'm able to copy/paste your code and compile it without issue in MSVC on Windows and g++ on linux.

@1-max-1
Copy link
Author

1-max-1 commented Sep 5, 2020

Oops, I was making a small change to the library and had temporarily commented out where it was defined. Completely forgot about it, that was the problem.

@1-max-1
Copy link
Author

1-max-1 commented Sep 5, 2020

Oh and just as a little side question, where would I place my .tmx files for android? Currently I have them in the app/src/main/assets folder but tmxlite says it failed to open the map because it couldn't find it.

@fallahn
Copy link
Owner

fallahn commented Sep 5, 2020

No problem, it happens to us all :)

You make a good point about opening files, however. It appears fstream doesn't actually work with the NDK (so why they include it, I don't know, especially when they don't implement std::to_string()). You'll have to convert the library to use fopen() or possibly even use SDL2's file system functions. I'll have to look into creating some sort of interface for custom file streams in the future. As a work around you could load the tmx file into a string then feed that into the map loader via Map::loadFromString() although this will likely fail if it needs to load external tileset files, for the same reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants