Page 1 of 1
SDL Level Editor
Posted: Sun Sep 28, 2008 10:45 pm
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
Re: SDL Level Editor
Posted: Mon Sep 29, 2008 3:25 am
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
Re: SDL Level Editor
Posted: Mon Sep 29, 2008 9:56 am
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.
Re: SDL Level Editor
Posted: Mon Sep 29, 2008 10:19 am
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.
Re: SDL Level Editor
Posted: Mon Sep 29, 2008 11:26 am
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.
Re: SDL Level Editor
Posted: Mon Sep 29, 2008 7:49 pm
by Azorthy
Thanks, and I know about vectors but I am not resizing, but I will keep that in mind.
Re: SDL Level Editor
Posted: Mon Sep 29, 2008 9:01 pm
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.
Re: SDL Level Editor
Posted: Tue Sep 30, 2008 12:38 am
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: