• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
David.M

Loading Levels

6 posts in this topic

I've done some searching but couldn't find a topic that was quite what I wanted so I apologize if this has been asked multiple times.

 

I'm currently working on a 2D platformer game and am contemplating how to deal with loading levels. I'm using [url=http://libgdx.badlogicgames.com/]LibGDX[/url] as my framework. I was wondering what you guys prefer to do for handling this. I might like to add a level editor eventually so I was thinking about having a simple text file with the maps and different numbers representing different tiles, i.e.

0022200000
0000121000
0111012200
1110020010
0111210011
0120101010

Where 0, 1, and 2 represent different tile images. Then I could just load it in one level at a time. What are my other alternatives? How do you prefer loading levels? Thanks,

 

David

0

Share this post


Link to post
Share on other sites
When working indexed tiles in the past I usually started out with a small tileset and implemented a loader that would read from text files as you described. Once I was happy with the runtime I'd create a map editor that saved to a simple binary format something like this:

str MAPF - first 4 bytes are a fourcc to verify that the file is the correct format
uint32 length - indicating length of the rest of the file (total file length minus 8) so I can read the rest into memory easily

uint32 width - in tiles
uint32 height
uint32 layers
uint32 zero - for alignment

Then it's just raw byte-width tile id's, row followed by row.

At runtime the dimensions would be loaded into a struct and that would be fed to a loader function that turned each width x height bytes into a layer and spat out the resulting map object. Internally the map class just stored each layer in the form of the data which had been read. I also supported animated tiles, so the map included some functionality for dealing with that. By associating the map object with a tileset texture it could be prompted to render at any x,y offset. In D3D it's simple to do because the D3DXSprite batcher can do the sorting for you, but in an API that doesn't have that you'd want to sort by tile to cut rendering time.

'Tiled' is in vogue at the moment. It's a nice little tool. You may want to look at that before going hardcore. I believe there's a lib for loading Tiled maps as well, though I don't know what it loads into. Honestly if I were to do this again I'd go the Tiled route.

http://www.mapeditor.org/
0

Share this post


Link to post
Share on other sites

I mean with the example you gave, you could just use a .bmp file and represent red as 1 white as 0 and blue as 2.

Why waste 54 bytes on a header? Just use raw data.

 

to save:

 

FILE * fileLevel;

fileLevel = fopen(NAME,"w");

fileLevel = fopen(NAME,"a");

for(int i = 0; i < LEVELHEIGHT; i++)

{

for(int j = 0; j < LEVELWIDTH; j++)

{

fputc((char)LEVELDATAARRAY[i][j],fileLevel);

}

}

fclose(fileLevel);

 

to open:

 

FILE * fileLevel;

fileLevel = fopen(NAME,"r");

for(int i = 0; i < LEVELHEIGHT; i++)

{

for(int j = 0; j < LEVELWIDTH; j++)

{

LEVELDATAARRAY[i][j] = fgetc(fileLevel);

}

}

fclose(fileLevel);

Edited by ProvenDantheman
0

Share this post


Link to post
Share on other sites

I mean with the example you gave, you could just use a .bmp file and represent red as 1 white as 0 and blue as 2.

Why waste 54 bytes on a header? Just use raw data.

 

to save:

 

FILE * fileLevel;

fileLevel = fopen(NAME,"w");

fileLevel = fopen(NAME,"a");

for(int i = 0; i < LEVELHEIGHT; i++)

{

for(int j = 0; j < LEVELWIDTH; j++)

{

fputc((char)LEVELDATAARRAY[i][j],fileLevel);

}

}

fclose(fileLevel);

 

to open:

 

FILE * fileLevel;

fileLevel = fopen(NAME,"r");

for(int i = 0; i < LEVELHEIGHT; i++)

{

for(int j = 0; j < LEVELWIDTH; j++)

{

LEVELDATAARRAY[i][j] = fgetc(fileLevel);

}

}

fclose(fileLevel);

 

Easier to modify, easy to visually see etc. Im ok with wasting 54bytes on a header file, when I have those added benefits!

0

Share this post


Link to post
Share on other sites

You can try checking out Programming Role Playing Games With DirectX by Jim Adams (2nd Ed) It uses DX9 but it help you to get started.

0

Share this post


Link to post
Share on other sites

Back in time I used... believe it or not... OpenOffice Calc. Exporting to .csv. It worked quite well. In retrospect, it worked better than my current approach which is giving me headaches right now.

The cool thing about using CSV is that you can have many, many tiles, with many, many properties and they'll still align as you want them to when opened in Calc. By contrast, a pure txt file would quickly require a lot of padding to align on number digits and extra annotations.

 

That said, I prefer binary blobs for runtime.

Edited by Krohm
0

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  
Followers 0