SDL Level Editor

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Azorthy
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 12
Joined: Sun Sep 28, 2008 10:37 pm

SDL Level Editor

Post by Azorthy »

So I am working on a level editor in SDL with the tutorial : http://lazyfoo.net/articles/article09/index.php And I have made my self one that uses a 240 array for the tiles, which limits me to the size of the level, and my question is : How would you make it so you could have 10,000+ tiles?

I think using nested loops with nested arrays could do the trick, like : The array holding arrays would be the y level so: Array[0] = ArrayNestedOne[256];
Being that Array is the major and ArrayNestedOne is the x pos of the tiles so thats 256 tiles. So is this a good approach?

Please help me, also I am using a sixteen by sixteen tile sheet.

Images:

Version One:

http://img508.imageshack.us/img508/2409 ... 011dx5.png
http://img206.imageshack.us/img206/5526 ... 012pn2.png
http://img259.imageshack.us/img259/1545 ... 013vf6.png
Last edited by Azorthy on Tue Sep 30, 2008 1:10 am, edited 1 time in total.
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: SDL Level Editor

Post by Moosader »

Azorthy wrote:So I am working on a level editor in SDL with the tutorial : http://lazyfoo.net/articles/article09/index.php And I have made my self one that uses a 240 array for the tiles, which limits me to the size of the level, and my question is : How would you make it so you could have 10,000+ tiles?

I think using nested loops with nested arrays could do the trick, like : The array holding arrays would be the y level so: Array[0] = ArrayNestedOne[256];
Being that Array is the major and ArrayNestedOne is the x pos of the tiles so thats 256 tiles. So is this a good approach?

Please help me, also I am using a sixteen by sixteen tile sheet.
What I have in my editor is a dynamic 3D array. The first dimension is the layer (which is only three), but then the max x and max y are dynamic and change based on what the user enters at the beginning of the program for what they want the level width and height to be.
In general for 2D maps, I wouldn't really store those in a 1D array, purely for readability sake.
You can have something like

class Level
{
TileClass tile[100][100]; //10,000 tiles, 100 horizontally, 100 vertically.
}

and the tile class would hold it's x and y coordinates, width and height, the position on the tile filmstrip, and collision properties and such.

I don't think it'd be wise to make a gigantic map, though. If you really try to make a 100x100 map you'll find that's... pretty big. Something smaller would probably be sufficient and, if not, you can always have separate maps and use some creative coding to make it seem like it's one big endless map (like Pokemon!)

If you're interested, my map editor (MusuGo) is open source so you can read what I have, or modify it as needed for your own use.
http://moosader.com/Resources.html
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: SDL Level Editor

Post by Falco Girgis »

I think she covered it.

edit: Just tell me that you're using C++ and not straight C. I can see your next question being "How do I allocate a dynamic 3D array in C?" With a lot of malloc() calls and a lot of Tylenol.
Azorthy
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 12
Joined: Sun Sep 28, 2008 10:37 pm

Re: SDL Level Editor

Post by Azorthy »

Thanks for the help, so it is indeed multi-dimensional arrays. and I need a big map for making a Island and using my new theory for storing the map would work really fast.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: SDL Level Editor

Post by MarauderIIC »

GyroVorbis wrote:I think she covered it.

edit: Just tell me that you're using C++ and not straight C. I can see your next question being "How do I allocate a dynamic 3D array in C?" With a lot of malloc() calls and a lot of Tylenol.
lolno see
http://www.elysianshadows.com/phpBB3/vi ... art=999999
http://www.eskimo.com/~scs/cclass/int/sx9b.html
http://www.velocityreviews.com/forums/t ... -call.html

You can also use a vector of vectors, if you want a dynamic 2d array in C++ and don't mind using STL. Note that this has the advantage of not taking up more memory than needed, but the disadvantage that resizing is slow, so calling vector.resize ( http://www.devx.com/tips/Tip/5328 ) ASAP is the best approach instead of multiple push_back()s.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Azorthy
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 12
Joined: Sun Sep 28, 2008 10:37 pm

Re: SDL Level Editor

Post by Azorthy »

Thanks, and I know about vectors but I am not resizing, but I will keep that in mind.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: SDL Level Editor

Post by MarauderIIC »

Azorthy wrote:Thanks, and I know about vectors but I am not resizing, but I will keep that in mind.
If your maps are different sizes, you could be =)
Essentially the point is that it removes the cap from your level sizes. If you want it to.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Azorthy
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 12
Joined: Sun Sep 28, 2008 10:37 pm

Re: SDL Level Editor

Post by Azorthy »

Thank you guys and girls so much.... I got a working level editor, I thought there was a problem and then I found out that my source wasn't showing the tiles =).
I will look into vectors and into the idea of picking a tile like Musugo, but in a separate window using aedGUI. And off to making huge levels, I am also taking pic's and I will post the source later this week once I got it user friendly.

Check the main post: Got some pics:
Post Reply