Advice for 2d level design in SFML

Started by
10 comments, last by Servant of the Lord 12 years, 1 month ago
I'd like to learn more about 2d level design. I've done some simple 2d games but i'm looking to get a little more complex in the future.
1. What is the best way to load and draw all of my sprite into my map.
2. How would i make a side-scroller (Isn't something about changing the sf::View)
3. What are the purposes of level editors and how do they work.
4. Anything else i should know.

I know i don't know nearly as much as i should, but that's why i'm here. :)
Advertisement

1. What is the best way to load and draw all of my sprite into my map.

Loading is simple, you just have a level file that tells you what resources it needs, then you load those resources

2. How would i make a side-scroller (Isn't something about changing the sf::View)

There are many ways to do this. You can change your view, or you can move the entire level, or... well, if you imagine it, you can probably find a way to do it.

3. What are the purposes of level editors and how do they work.

Level editors make it easy to create content. In essence you have a GUI application that you do your work in, which when saved translates the data into a level format you recognize.

4. Anything else i should know.

Experiment and play around. Google a lot, there are a lot of people who have written things on side scrollers and the like. While they may not all use SFML, you can certainly pick up tips and tricks to use.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

I still don't understand level editors at all. Are they worth using? How do they work with your program?

I still don't understand level editors at all. Are they worth using? How do they work with your program?


Ok, think of it like this, how would you plot all the positions of every object/tile in your level? by manually inputting all the coordinates? seems a bit tedious.. you could come up with a file format which tiles different sprites based on a number index in text file. Such a file might look something like this:

w h
1 1 1 1 1 1 1 1
1 0 0 0 0 0 2 1
1 0 0 0 0 1 1 1
1 1 1 1 0 0 0 1
1 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1

where 0 represents empty space 1 a solid block and 2 something else. However this becomes tedious to edit/manage when levels become large with more than a few different types of objects, also if your not using a tile based system this will fail altogether.

Enter the Map/Level Editor, a tool that allows you to design levels visually which makes managing large levels easier with the ability to supply additional information such as collision/layers objects that exist in the map, tiles and more. Generally, the map editor will output all the necessary data in a file which can then be read by your application that runs the game.

In the end a Map/Level editor does what an useful tool does.. makes your job easier.
Ok that clears a lot up, thanks for helping out.
If you're talking about a shoot-em up side-scroller, then, one common solution for "levels" is to create your "levels" details when and where objects/enemies appear on your screen. Typical space shoot-em ups, the main ship is always moving (right, for side scrolling, up for vertical), so you just plug in when to make an object appear.

I did this long ago (2001 or so, I was still learning) for an old game, and my "levels" looked like this:
(The 1st number is the time in Milliseconds after the level starts.
E: stands for Enemy, B: stands for Background, M: stands for Music, S: for sound
Most of my objects had default X, Y, speeds, etc/ but I could change them here too. If I did it now, I would've probably used xml)


# The format for the stage is like follows, it must be in order!
# Time enemy (or Background object) should appear since start (in mS)
# Enemy (or BackGround object) Name
# Flags (should be 0)
# Any other enemy attribute you want to change from default

# start music
250
M:stage1.wav

# Back Grounds
2500
B:Moon
0

500
B:Hills
0

65000
B:Moon
0

# Flags 131078 = SPECIAL_ENEMY | WEAPON_UPGRADE | WEAP_PLASMA
#1100
#E:Special
#0
#Flags: 131078

# Enemies/Objects
1500
E:Orb
0

2000
E:Orb
0

2500
E:Orb
0

3000
E:Orb
0

3500
E:Orb
0


5000
E:Special
0

10000
E:Fighter
0

15000
E:Special
0
LocationXY: 640 80
SpeedXY: -134 -134

20000
E:Skimmer
0
LocationXY: 640 10

20000
E:Fighter
0

23500
E:Orb
0

24000
E:Orb
0

25500
E:Orb
0
LocationXY: 640 400

26000
E:Orb
0
LocationXY: 640 400

28000
E:EMP
0
LocationXY: 640 50

31000
E:Orb
0

31500
E:Orb
0

32000
E:Orb
0

32500
E:Orb
0

33000
E:Orb
0

31000
E:Orb
0
LocationXY: 640 400

31500
E:Orb
0
LocationXY: 640 400

32000
E:Orb
0
LocationXY: 640 400

32500
E:Orb
0
LocationXY: 640 400

33000
E:Orb
0
LocationXY: 640 400

# Flags 10 = SPECIAL_ENEMY | NEW_OPTION
33000
E:Special
0
Flags: 10

34100
E:Fighter
0

35000
E:Orb
0

35500
E:Orb
0

36000
E:Orb
0

35000
E:GunTower
0
LocationXY: 640 446

41000
E:Skimmer
0
LocationXY: 40 400
SpeedXY: 268 0

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)


I'd like to learn more about 2d level design. I've done some simple 2d games but i'm looking to get a little more complex in the future.
1. What is the best way to load and draw all of my sprite into my map.
2. How would i make a side-scroller (Isn't something about changing the sf::View)
3. What are the purposes of level editors and how do they work.
4. Anything else i should know.

I know i don't know nearly as much as i should, but that's why i'm here. smile.png


1. It depends. From what I've seen, resources are loaded from the "map file" whenever they are needed for the game. For instance, there was a game that needed a long level. This level was divided by a certain amount of screens (the portion of the level viewed by the player). Whenever this portion of the level was approached, these portions were loaded in a thread so when said player entered the portion, the level was already loaded and the future portion was being loaded.

2. Side-scrollers consist of a "camera" following a player as he/she progresses horizontally. To achieve this affect, programmers take the "view" (a difference between the initial level coordinates and the current displacement to achieve this "camera" effect. I.e. If a player holds a KB_RIGHT_KEY (keyboard right key), some variable x_displacement will increase.) So we'll have (x_origin - x_displacement) = cam_x; If the x_origin is 0, then the displacement will be -x_displacement from the screen. (movement to the right will be moving everything to the left). It's smart trickery. ;)

3. Level editors allow you to view the level as you make it graphically. Some editors are so advanced to allow you to place objects as you see fit (with properties) and load them in your own time. Save's a lot of dev time!

4. Know your geometry. 2D games consist of geometry and the more complex your games become, the more complex the geometry may come to. For instance, I came to a point when I needed to know what angle some wall would be moving my colliding object (pseudo physics), so that it would move out of the wall's way and continue to move in some direction it was headed. Geometry really comes into play.
I'm that imaginary number in the parabola of life.
Does anyone know a good 2d level/map editor out there. It needs to be free and I'd like for it to be able to make good quality games and I'd like for it to be open source.
Tiled or Mappy or Gleed2D, depending on your needs. Note, they won't make your game for you, nor do they teach your game to read their files.
You still have to make your game, and you still have to teach your game to read their file formats. This may be difficult if you've never done it before, but if you are persistent, it'll definitely be worth it.
Can I use tiled with sfml?

This topic is closed to new replies.

Advertisement