0 Members and 2 Guests are viewing this topic.

#### Kebrian

• Newbie
• Posts: 9
« Reply #15 on: February 07, 2013, 11:18:52 am »
I have not long time ago such problems too. What i see make sure that tmx maps are readed good. There is 3 whitespaces on begining of each data tag- make sure not to read this. And sometimes there is no '=' character on end of base64 encoded maps.

#### Spunkt

• Newbie
• Posts: 3
« Reply #16 on: February 08, 2013, 07:52:35 am »
Well, I dont know what it is. I've notice that each time that I have any kind of tile information in the TMX file I get an Assertion Error and when I dont have any tile information I get a "Bad map. No tile information found" but the program is running. Not quite sure how to load the tile information then. Btw I'm using the SFML 2.0, and the tile information that don't work is all the
"<tile gid="7"/>" that is in the file.

Anyone that might have a suggestion ?

« Last Edit: February 08, 2013, 07:58:08 am by Spunkt »

#### fallahn

• Full Member
• Posts: 229
« Reply #17 on: February 11, 2013, 03:03:08 pm »

#### Spunkt

• Newbie
• Posts: 3
« Reply #18 on: February 12, 2013, 07:52:36 am »
Thanks! Looks like I had some problem loading the objects. The program never really accepted that some objects had GID and some did not. But looks like it works now with the help of your:
int gid = (objectElement->Attribute("gid")) ? atoi(objectElement->Attribute("gid")): 0;

EDIT*
I've been thinking, after a lot of searching in the code example you posted, I only see that you can draw the "normal" layers, but if I wanna draw the object tile (if I have one) can I like put it all in a if/else to have the code go one way if there is a "normal" layer or the other if there is a object layer.
Really been stuck on this today.

Thanks
« Last Edit: February 12, 2013, 07:01:28 pm by Spunkt »

#### fallahn

• Full Member
• Posts: 229
« Reply #19 on: February 13, 2013, 12:32:11 pm »
When parsing the object layer you can do something like this:

if(gid) m_SetTile(subrects, layer, x, y, gid);

which will add a sprite to the rendering layers based on the object gid and x/y coords if the gid is non-zero.

#### Mmarzex

• Newbie
• Posts: 8
« Reply #20 on: February 23, 2013, 03:05:23 am »
How would you use the 2.0 version with an sf::View. Is that the best way to do it for something involving a 2d platforming game with a player moving?

#### fallahn

• Full Member
• Posts: 229
« Reply #21 on: February 24, 2013, 12:29:26 pm »
Just move the sf::view around your world as you normally would then use TileMap::SetDrawingBounds() to set the drawing rectangle to that of your current view

#### Mmarzex

• Newbie
• Posts: 8
« Reply #22 on: February 24, 2013, 04:12:59 pm »
This may be a stupid question but SetDrawingBounds does that limit the tilemap to only be drawn on those specific sections of the tilemap itself or with regards to how it is drawn on the screen?

#### fallahn

• Full Member
• Posts: 229
« Reply #23 on: May 30, 2013, 11:21:02 am »
Wasn't really sure if I should drag up this old topic or start a new one, but I've completely rewritten this class. I decided to post here to make sure the original author gets credit for his work which started the whole thing in the first place. I've written a post about it here which includes a download with some examples but for brevity here's the readme:

Code: [Select]
`This class is designed to load TILED .tmx format maps, compatible withTILED up to version 0.9.0http://trederia.blogspot.co.uk/2013/05/tiled-map-loader-for-sfml.htmlWhat's Supported----------------Uses pugixml (included) to parse xmlSupports orthogonal mapsSupports isometric mapsSupports conversion between orthogonal and isometric world coordsParses all types of layers (normal, object and image), layer propertiesParses all type of object, object shapes, types, propertiesOption to draw debug output of objects, grid and object namesSupports multiple tile sets, including tsx filesSupports all layer encoding and compression: base64, csv, zlib, gzip and xml (requires zlib library, see /lib directory)What's not supported / limitations----------------------------------Parsing of individual tile propertiesFlipping / rotation of spritesStaggered isometric mapsTile set images must be in the same directory as tmx/tsx filesTo display object names when drawing object debug shapes then you must provide a fontand update MapObject.hUsage-----To quickly get up and running create an instance of the MapLoader class    tmx::MapLoader ml("path/to/maps");load a map file    ml.Load("map.tmx");and draw it in your main loop    ml.Draw(renderTarget);Note that the constructor takes a path to the directory containing the map files as a parameter (withor without the trailing '/') so that you only need pass the map name to MapLoader::Load(). Currentlyall map files (tmx, tsx, images etc) must be in the diretory passed to the constructor.New maps can be loaded simply by calling the load function again, existing maps will be automaticallyunloaded. MapLoader::Load() also returns true on success and false on failure, to aid running the functionin its own thread for example. Conversion functions are provided for converting coordinate spaces betweenorthogonal and isometric. For instance MapLoader::OthogonalToIsometric will convert mouse coordinates fromscreen space:    0--------X    |    |    |    |    |    Yto Isometric space:      0     / \    /   \   /     \  /       \ Y         XLayer information can be accessed through MapLoader::GetLayers()        bool collision;    for(auto layer = ml.GetLayers().begin(); layer != ml.GetLayers().end(); ++layer)    {        if(layer->name == "Collision")        {            for(auto object = layer->objects.begin(); object != layer->objects.end(); ++object)            {                collision = object->Contains(point);            }        }    }For more detailed examples see the source for the demos.Requirements------------pugixml (included)zlib (http://zlib.net/)SFML 2.0 (http://sfml-dev.org)`
as well as being a rewrite, it contains quite a few enhancements / new features.

This may be a stupid question but SetDrawingBounds does that limit the tilemap to only be drawn on those specific sections of the tilemap itself or with regards to how it is drawn on the screen?

SetDrawingBounds is used to define which tiles are visible, to save drawing tiles which don't need to be drawn. In the new version it is called automatically by Draw using the view of the supplied renderTarget.

#### DJuego

• Newbie
• Posts: 43
« Reply #24 on: May 30, 2013, 01:24:44 pm »
I think it is the more advanced  tmx parser 'released' for SFML in this moment. Thank you for your contribution fallahn!

I propose you open your own thread in SFML projects for more and better visibility and feedbacking with a feature list and so... Your work deserves it!

A git repository will be welcomed too.

Thanks again!

DJuego
« Last Edit: May 30, 2013, 01:39:20 pm by DJuego »

#### NathanielSheller

• Newbie
• Posts: 4
« Reply #25 on: June 14, 2013, 01:32:44 am »
I am having issues using this loader.

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <level.h>

int main(){

sf::RenderWindow window(sf::VideoMode(640, 480), "");

sf::View view;
view.setCenter(player_x, player_y);
view.setSize(640, 480);

Level sample_map;
sample_map.SetDrawingBounds(view.getViewport());

while (window.isOpen()){
sf::Event event;
while(window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();

}

window.clear(sf::Color::Green);

window.setView(view);

sample_map.Draw(window);

window.display();
}
return 0;
}

#### fallahn

• Full Member
• Posts: 229
« Reply #26 on: June 14, 2013, 08:35:19 am »
If I were to hazard a guess its because you are using the full path to the map file when the loader expects a path relative to your executable. That being said it also looks like you are using the older version of the map loader - there is a much updated version here which allows you to construct the loader with a path to your map directory, so you only have to pass the map name to the Load function.

#### NathanielSheller

• Newbie
• Posts: 4
« Reply #27 on: June 14, 2013, 12:05:56 pm »
Thank you very much , but I am getting a few error messages when trying to use your loader.

Quote
C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   In member function 'const bool tmx::MapObject::Intersects(tmx::MapObject&)':
159   13   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'i' does not name a type
159   47   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] expected ';' before 'i'
159   47   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'i' was not declared in this scope
159   65   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'class std::vector<sf::Vector2<float> >' has no member named 'cend'
162   13   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'i' does not name a type
162   40   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] expected ';' before 'i'
162   40   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'i' was not declared in this scope
162   58   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'class std::vector<sf::Vector2<float> >' has no member named 'cend'
C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   In member function 'void tmx::MapObject::CreateDebugShape(sf::Color)':
172   13   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'i' does not name a type
172   40   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] expected ';' before 'i'
172   40   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'i' was not declared in this scope
172   58   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'class std::vector<sf::Vector2<float> >' has no member named 'cend'
C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   In member function 'void tmx::MapObject::m_CalcTestValues()':
264   13   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'i' does not name a type
264   40   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] expected ';' before 'i'
264   40   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'i' was not declared in this scope
264   58   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\inc\map_loader\MapObject.h   [Error] 'class std::vector<sf::Vector2<float> >' has no member named 'cend'
71   14   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected unqualified-id before 'or' token
73   5   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before 'or' token
73   8   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before '==' token
77   10   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before 'or' token
77   13   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before '==' token
84   38   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before 'or' token
84   41   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before '<<' token
272   14   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'i' does not name a type
272   33   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'i' was not declared in this scope
272   43   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'std::string' has no member named 'cend'
548   11   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'std::string' has no member named 'pop_back'
666   11   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'tile' does not name a type
666   39   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'tile' was not declared in this scope
736   4   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'memcpy' is not a member of 'std'
46   0   c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\cwchar   In file included from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/cwchar
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\postypes.h                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/bits/postypes.h
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\char_traits.h                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/bits/char_traits.h
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\string                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/string
961   17   c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\wchar.h   [Note] 'memcpy'
758   2   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'memcpy' is not a member of 'std'
46   0   c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\cwchar   In file included from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/cwchar
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\postypes.h                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/bits/postypes.h
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\char_traits.h                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/bits/char_traits.h
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\string                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/string
961   17   c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\wchar.h   [Note] 'memcpy'
« Last Edit: June 14, 2013, 12:30:27 pm by NathanielSheller »

#### fallahn

• Full Member
• Posts: 229
« Reply #28 on: June 14, 2013, 01:38:04 pm »
Ah I forgot to mention it uses C++11 features, particularly the auto keyword. In g++ you need to add

-std=c++0x

or

-std=c++11

to the compiler options (I think - I haven't actually tried compiling with anything other than VS10  )

#### NathanielSheller

• Newbie
• Posts: 4
« Reply #29 on: June 14, 2013, 06:15:50 pm »
Ahhhh ty )

Edit: Still not compiling correctly :/

Quote
71   14   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected unqualified-id before 'or' token
73   5   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before 'or' token
73   8   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before '==' token
77   10   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before 'or' token
77   13   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before '==' token
84   38   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before 'or' token
84   41   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] expected primary-expression before '<<' token
736   4   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'memcpy' is not a member of 'std'
46   0   c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\cwchar   In file included from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/cwchar
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\postypes.h                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/bits/postypes.h
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\char_traits.h                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/bits/char_traits.h
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\string                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/string
961   17   c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\wchar.h   [Note] 'memcpy'
758   2   C:\Users\Natha_000\Desktop\Blood of Tyr Prototype\src\map_loader\MapLoaderPrivate.cpp   [Error] 'memcpy' is not a member of 'std'
46   0   c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\cwchar   In file included from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/cwchar
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\postypes.h                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/bits/postypes.h
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\char_traits.h                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/bits/char_traits.h
42      c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\string                    from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/string
961   17   c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\include\wchar.h   [Note] 'memcpy'
« Last Edit: June 14, 2013, 07:13:46 pm by NathanielSheller »

anything