Sign in to follow this  
SoulHeart

Advice for 2d level design in SFML

Recommended Posts

SoulHeart    101
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. :)

Share this post


Link to post
Share on other sites
Washu    7829
[quote name='SoulHeart' timestamp='1329763899' post='4914902']
1. What is the best way to load and draw all of my sprite into my map.
[/quote]
Loading is simple, you just have a level file that tells you what resources it needs, then you load those resources
[quote name='SoulHeart' timestamp='1329763899' post='4914902']
2. How would i make a side-scroller (Isn't something about changing the sf::View)
[/quote]
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.
[quote name='SoulHeart' timestamp='1329763899' post='4914902']
3. What are the purposes of level editors and how do they work.
[/quote]
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.
[quote name='SoulHeart' timestamp='1329763899' post='4914902']
4. Anything else i should know.
[/quote]
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.

Share this post


Link to post
Share on other sites
CodeCriminal    290
[quote name='SoulHeart' timestamp='1329774976' post='4914970']
I still don't understand level editors at all. Are they worth using? How do they work with your program?
[/quote]

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.

Share this post


Link to post
Share on other sites
BeerNutts    4401
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)
[code]

# 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
[/code]

Share this post


Link to post
Share on other sites
KanonBaum    277
[quote name='SoulHeart' timestamp='1329763899' post='4914902']
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. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]

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 [i]being[/i] 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.

Share this post


Link to post
Share on other sites
SoulHeart    101
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.

Share this post


Link to post
Share on other sites
[url="http://www.mapeditor.org/"]Tiled[/url] or [url="http://tilemap.co.uk/mappy.php"]Mappy[/url] or [url="http://gleed2d.codeplex.com/"]Gleed2D[/url], 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.

Share this post


Link to post
Share on other sites
lmbarns    460
I haven't used sfml but I don't see why you couldn't use Tiled to layout your maps. If you save a map as .tmx and open it in a text editor you can copy the array of tiles it created and use that in your code.

So you visually can make a map in tiled by drawing your tiles based off your sprite sheet, save it as .tmx, copy the array, load the original sprite sheet in your program, loop through the array and draw corresponding tile from sprite sheet based off array entry.

Here's a visual example using just basic javascript and html5 that loads 500x300, 64-pixel tiles based off a sprite image http://simplehotkey.com/Tiles/main.html if you could reproduce that in c++ you'd have it made.

Share this post


Link to post
Share on other sites
[quote name='SoulHeart' timestamp='1330266983' post='4916717']
Can I use tiled with sfml?
[/quote]
Certainly. But like all programming, you have to make the 'glue' between piece one (SFML) and piece two (Tiled's maps).
It will take some work, and you'll face some challenges, but without difficulties to overcome, we don't grow as programmers.

If that's too daunting a task, someone else [url="http://tiledsfmlloader.sourceforge.net/"]has already made some glue[/url] between those pieces that you can re-purpose for your project, and you'll still have to figure out how to use it, and how it will work within the structure of your game.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this