SFML - Tile maps

Started by
2 comments, last by BeerNutts 12 years ago
I will try to not be vague so i can get some real help here.. so please bear with me..

I am tying to learn SFML I am not new to C++. What i want to do is make a map and have an animation sprite move around and have boundaries
and interact with objects. I have an animation class and a player class where i am loading and displaying a sprite sheet and moving him around the screen(animation) for a player(not perfect but works).


What i am confused about is making the maps and displaying them and setting boundaries for the player. I hear terms like level, layer but unsure what they really mean to game design, and how they all work with the map and the player animations, collision detection etc.. I want to make a 2D rpg type tile game. something like zelda or chrono trigger, final fantasy.


I am trying to understand the structure.
The first layer allows you to define a basic landscape.
A second layer allows you to decorate it with trees, chairs, or other objects.
A third layer contains your sprites? Are sprites just like enemies, players, etc? Or can they be a whole map?
fourth layer defines the boundaries inside which the sprites can move.

Question #1
Is this all done when i make the map?
Do i define the layers in C++ code?

Please forgive me if i seem to have a lot of questions below.

Question: #2
I want to make a map and set boundaries( collision detection?) and move the player sprite around the map.

I am just not sure where to start. Can i use something like tiled map editor? do i make one big map that consists of the entire game or do i make a map for each screen size? Do i just then add it to a data structure and then load it to the screen when needed?


I was looking over this tutorial on developing a SFML C++ tile engine from scratch.
http://www.dreaminco...5

He doesnt go into the map making process at all.
he mentions XML which i am familiar with and xaml but unsure how to use it. XML seems like something that could be easy to use with SFML? Seems like good guide but unsure how XML fits in with the map making process!

Can anyone give me some guidance on how the tile map process works with layers, etc..?
I guess i am just confused on the process. Sorry if it seems like i have a lot of questions. I tried to shorten it so someone will help me.
I have been threw most of what i can find for SFML
Advertisement
Well there isn't really a specific way to do it(like anything in game development), but perhaps I could offer some guidance as I'm making a tile based game too. There isn't really anything special to tile layers; it's just a term given to maps that can be layered on top of each other. You could even have one layer in your whole game, but you can see how that wouldn't work out. If a there was a 5X5 area of grass and you wanted to put a tree on it, then in between the branches you would just see whatever colour the background is because you replaced the grass tile that was there before. Some people tackle this by adding another layer to place the tree on. That way the first layer has grass on it, and the tree looks like it's on top. You might have to use multiple layers for multiple trees that are overlapping to get the effect you want though. Personally, I'm only having probably one tile layer in my game. This will be for basic landscape stuff like grass, dirt, etc. Then I will have an object layer where I will have pre-made objects(which can be trees, flowers, bad guys, houses, etc.) and my engine will take their positions and determine how to draw them.

For starters, you could get your character to collide with the edges of the screen. For example, to collide with the left side of the screen, you would check if the player's x position was less than 0, and if so, set it to 0.

Next you'll want to be able to draw tiles on the screen. You could represent a tile map using an array of integers. Different numbers would represent different tile textures that you would have to draw. So a 3X3 array of '0's would be a map that represents a 3X3 grid of grass tiles while '1's might be water or something. You could these numbers from a text/binary file or an XML file or something. Since you were wondering about XML, it's basically just a human-readable way to store information. XML files don't really do anything(in a sense), it's up to your program to interpret it.

One more suggestion is that since you are using SFML, you can use "views" to move the camera around. Check the SFML website for how to use them.

Now for my best piece of advice. My post is relatively vague, but everything I mentioned is covered in Nick Gravelyn's tile engine tutorials. It's written in C# and he does a lot more stuff like creating a tile editor, but you can still apply his stuff to your C++/SFML game. Look up "NIckGravelyn" on youtube.

Good luck. Feel free to ask any questions if you want.
@bones, I understand most of what you said. I understand in programming there are many ways to do things. I understand the layers thing because it sounds like photoshop.


So, i looked over his first 2 videos on loading and displaying tiles. This is very helpful. I will take what he is doing and apply it to SFML C++

Whats confusing is he seems to be scrolling the map. I thought you are suppose to scroll the map only when the play reaches the end.

@bones, I understand most of what you said. I understand in programming there are many ways to do things. I understand the layers thing because it sounds like photoshop.


So, i looked over his first 2 videos on loading and displaying tiles. This is very helpful. I will take what he is doing and apply it to SFML C++

Whats confusing is he seems to be scrolling the map. I thought you are suppose to scroll the map only when the play reaches the end.


He talks about creating the map in part 4:
http://www.dreamincode.net/forums/topic/232396-c-tile-engine-from-scratch-part-4/

Now, about scrolling, typically, you want your character to always be in the middle of the screen, so, every time the player moves a square, you should scroll the background. If the character reaches the end of the map, you may want to stop scrolling, and just have the player move to the edge of the screen then, but, I typically continue to scroll, and just show black for the out-of-bounds area of the map.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement