10 Replies - 2321 Views - Last Post: 30 November 2011 - 10:41 AM Rate Topic: -----

#1 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 09:02 AM

Hello people!

Im making a Side-Scroller game in C++ using the SDL library, And this is my first game i am creating.

I was thinking how the maps would be built and i was thinking of two options, Draw the whole map in a .png and then write in code what cordinates should have collision and so on.. Or i could make a sprite sheet full of tiles and load each tile to the screen where i want them using an array or something.

I found out that option number two would be a better way. Now im wondering if there is somewhere i can read about making something like a Tile Map loader or something..

I don't want the code i want to solve this myself with my own code. Im intrested in learning this not copy paste.

Is This A Good Question/Topic? 0
  • +

Replies To: Best way to solve "Loading tile maps"?

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 09:15 AM

The way I usually do this in XNA, although different langauges, libraries and frameworks than C++ with SDL this method should still work, is I keep an XML file with data for each tile including the texture used for that tile, whether or not it has collision, position on the screen, and any special features such as height if I wanted to create a map with multiple height levels, etc. I then deserialize this data into an object for each tile that is on that particular level in the game and add those to an array. Then it's just a matter of drawing each of the tiles to the screen using the information for each of the objects.

This post has been edited by Kilorn: 30 November 2011 - 09:19 AM

Was This Post Helpful? 0
  • +
  • -

#3 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 09:25 AM

View PostKilorn, on 30 November 2011 - 04:15 PM, said:

The way I usually do this in XNA, although different langauges, libraries and frameworks than C++ with SDL this method should still work, is I keep an XML file with data for each tile including the texture used for that tile, whether or not it has collision, position on the screen, and any special features such as height if I wanted to create a map with multiple height levels, etc. I then deserialize this data into an object for each tile that is on that particular level in the game and add those to an array. Then it's just a matter of drawing each of the tiles to the screen using the information for each of the objects.


Very Very intresting idea!

But from what i read here: http://www.artima.co...ta_binding.html
It will be little complicated.. But thats okay, Also if i would use XML like this would it be possible to call it Script? In my eyes this would be almost the same as a script except here i only use it to store values about my maps.
Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1010
  • View blog
  • Posts: 4,213
  • Joined: 14-February 08

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 09:33 AM

You could use Tiled, that's what I use. It will spit out an XML file for you to load in. The format is quite simple but you will need to decode the base64 information in your project. There are libraries that do this so no biggy.

Hope that helps :)
Was This Post Helpful? 0
  • +
  • -

#5 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 09:38 AM

View Poststayscrisp, on 30 November 2011 - 04:33 PM, said:

You could use Tiled, that's what I use. It will spit out an XML file for you to load in. The format is quite simple but you will need to decode the base64 information in your project. There are libraries that do this so no biggy.

Hope that helps :)


If i'm correct, This Tiled application is also capable of adding which objects is solid and which the player can walk through?

I see on the screenshots its a red cross over some tiles.. So this is just pure guessing. But i will download this application, It sounds very good!, Thanks!

This post has been edited by TheCompBoy: 30 November 2011 - 09:38 AM

Was This Post Helpful? 0
  • +
  • -

#6 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1010
  • View blog
  • Posts: 4,213
  • Joined: 14-February 08

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 09:51 AM

Well it is just a case of adding an attribute to the tile type, such as passable and then load it in. It doesn't automatically allow you to do this and most other tile editors won't either. You have to interpret the output file as needed.
Was This Post Helpful? 0
  • +
  • -

#7 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 09:59 AM

stayscrisp I made a map now in tiled.. But i think you were wrong about it spitting out .xml file.. For me when i go "Export As.." I can pick .lua .dat and .wlk

Maybe Lua would be a good idea to learn use :)?
Was This Post Helpful? 0
  • +
  • -

#8 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1010
  • View blog
  • Posts: 4,213
  • Joined: 14-February 08

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 10:02 AM

If you read the description of the application

Quote

General purpose tile map editor with XML-based map format


Yes it doesn't output .xml files, but they are XML based and can be loaded in using any XML loader. I wouldn't bother with LUA just for tile maps.
Was This Post Helpful? 0
  • +
  • -

#9 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 10:11 AM

Where can i read about how i would parse theese .TMX files into my C++ project.. And what the XML files contains.. I browsed the web but no success.. :S

And i think this isn't the same as parsing normal xml.. Or is it?

This post has been edited by TheCompBoy: 30 November 2011 - 10:16 AM

Was This Post Helpful? 0
  • +
  • -

#10 Fib  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 161
  • View blog
  • Posts: 554
  • Joined: 12-March 09

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 10:39 AM

The .tmx file Tiled outputs is literally the exact same as .xml with a different ending. So you can open up the .tmx file with any xml editor, or you can simply open it up with any text editor such as wordpad. This will allow you to see the contents, which should give you a better perspective on how to parse the file.
Was This Post Helpful? 0
  • +
  • -

#11 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Best way to solve "Loading tile maps"?

Posted 30 November 2011 - 10:41 AM

View PostFib, on 30 November 2011 - 05:39 PM, said:

The .tmx file Tiled outputs is literally the exact same as .xml with a different ending. So you can open up the .tmx file with any xml editor, or you can simply open it up with any text editor such as wordpad. This will allow you to see the contents, which should give you a better perspective on how to parse the file.


Thousand thanks!

I will go do this right away and try use my map that i created.. Thanks again everyone!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1