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

Author Topic: 2D Tile Based RPG Questions  (Read 2127 times)

0 Members and 1 Guest are viewing this topic.

mbuckley2000

  • Newbie
  • *
  • Posts: 7
    • View Profile
2D Tile Based RPG Questions
« on: December 22, 2013, 01:05:37 pm »
Hey,
I am developing a Tile Based 2D map editor for my game (Zelda style). So far, all is going well except I am noticing rather slow FPS in some scenarios. I have a few questions regarding this, and would appreciate any help :)

1. To store the sprites for each tile, I have been declaring an array like this in the globals:
sf::Sprite TileSprite[MaxXTiles][MaxYTiles][MaxZTiles];
My assumption with this was that this wouldnt slow down performance unless the sprites were being drawn, which only happens when they are textured. Is this a correct assumption to make? if not, should I be using another system such as dynamic arrays?

2. This is more of a general RPG game theory question.. At the moment, when a tile is selected from a tileset, that tile's texture rectangle, texture pointer and tileset filename are stored. When placed, I set the new tile's rectangle and texture equal to the one on the tileset. When saving, I save the rectangle and the tileset filename. Is this is the best way to do things? If not, how should I be doing it?

3. What is the usual way to save map data for this kind of game? I have seen other projects use XML, but I am unfamiliar with XML, so I am wondering whether it is viable to use the fstream commands included with C++?

Matt

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: 2D Tile Based RPG Questions
« Reply #1 on: December 22, 2013, 01:15:25 pm »
1. Use sf::VertexArray instead of sf::Sprite. There is a SFML tutorial explaining exactly this use case. Furthermore, avoid global variables, you almost never need them. Create a TileMap class that stores the tiles.

2. It's one possible way, but you could also have an enum that refers to the different tilesets, and serialize that (either as int, or write a std::string conversion function).

3. There are loads of ways. Besides the traditional formats like XML or JSON, you can create your own binary or text format. You can use script languages such as Lua to store configuration data, or you can use serialization libraries like Google's protobuf or Boost.Serialize. For the beginning, I would keep it simple and create a text format that can be loaded and saved with std::fstream.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

mbuckley2000

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: 2D Tile Based RPG Questions
« Reply #2 on: December 22, 2013, 01:25:51 pm »
OK thanks that's very helpful :)