Allegro.cc Forums » Programming Questions » Isometric madness

 This thread is locked; no one can reply to it. 1   2   3
 logan666 Member #2,024 March 2002 Hi, Im working in an isometric demo, up to now i got the projection working. I use this simple piece of code to get the job donefor(my=0; my< 30; my++ ){ for(mx=0; mx< 30; mx++ ) { sx=( mx * TILEM_W ) - ( my * TILEM_W ); sy=( my * TILEM_H ) + ( mx * TILEM_H ); masked_blit(tile,buffer,0,0,sx+SCREEN_W/2 -32 x,sy+cy,64,32); } }As you can read the map is 30 x 30, tiles are 64 x 32. The problem is how to draw only what is seen in a given moment and not drawing the entire map every time, so that drawing speeds up with bigger maps.Im still trying a couple of ideas I came up with but havent succeed.Any one has an idea to help solve this isometric maddness?:-[ ================"La gente, humana, para desprestigiarle dicen que no es un genio pero que vive dentro de una botella" - Jorge Martinez -
 DanielH Member #934 January 2001 Figure out which tiles will be seen and only draw those. Take the camera position and use that as the center. Go out from the center a few tiles until you are sure that the view area will be completely covered. Then draw it. In my isometric game, I have a 14x14 grid of tiles, but I draw a 30x40 grid of tiles to cover any missing areas. The vertical postion at the bottom might need some extra if you have a height to the tiles. I have a few tall tiles. they were disappearing instead of scrolling of the screen. I had to adjust the height until they no longer 'disappeared'. The source code might not be understandable, but you can download my isometric source. 'Daython's Quest' from the link in my sig. Look under 'mygames'.I created a template for the grid size. I calculated the position of the template when the game is initialized. And I use that template throughout the game to find the position of the mouse, etc...
 spellcaster Member #1,493 September 2001 Don't draw diamond shaped maps.It's way harder to draw them, way hareder to find the mouse position, etc.Simply draw the map the way you'd draw a normal rectangular map. But: For every row increase y only by half the tileh eight and offset x every other row by half the tile width.If you want diamond shaped levels, simply put only visible tiles there, and use transparen tiles around them.Did this make sense? --There are no stupid questions, but there are a lot of inquisitive idiots.
 lameDuck Member #2,327 May 2002 I'm curious again:) In an isomentric game, how to you handle the sprite drawing order. You must have to blit the one that are further away in the Y direction first? Or have I just answered it, loop through all the visible sprites checking their Y positions...
 DanielH Member #934 January 2001 You might want multiple layers.I have multiple layers.I draw the ground firstthen any buildings/wallsthen any roofs.I draw the people sprites in the middle of drawing the walls. Draw all the that are farther away first. then draw the sprite. Then repeat for next sprite.and about the diamond shapes maps. Now you tell me. Oops. Because of the order of drawing, that is why I have a diamond shaped drawing ``` 0 1 2 3 4 5 6 7 8 9 A B C D E F ``` And it was hard to draw it. That's when I came up with the template system. I calculated the position for each tile before hand. Then all I had to do to draw it was draw the tilesdraw_map()for int i = 0 to MAXTILES i++template.draw(i);
 logan666 Member #2,024 March 2002 Daniel Hwhat is the idea behind your template system ? ================"La gente, humana, para desprestigiarle dicen que no es un genio pero que vive dentro de una botella" - Jorge Martinez -
 DanielH Member #934 January 2001 There are too many calculations done in the map drawing. By doing all the calculations once in the template there are very little left during drawing. So far I get 80+ FPS.
 lameDuck Member #2,327 May 2002 I like the idea. How daft is this. I'm barely 20% through my first game and I'm already planning my second!!!
 spellcaster Member #1,493 September 2001 Draw the map like this:``` 0 1 2 3 4 5 6 7 8 9 a b c d e ``` Now imagine that the lines are half the tile height apart... like this:http://www.steinke.net/download/iso.gifSee? That way you can use a slightly altered rect map drawing algorithm. --There are no stupid questions, but there are a lot of inquisitive idiots.
 Oscar Giner Member #2,207 April 2002 spellcaster: I did my isometric engine just like you (only that I have also height, so it's semi 3D . But that depends on the game. --[Website | e-mail][Tetris Unlimited] [AllegAVI | AlText]
 logan666 Member #2,024 March 2002 Spellcaster:I got the isometric stuff working with non diamond shaped maps, think its a better way to go, thanks for the advice.8-) ================"La gente, humana, para desprestigiarle dicen que no es un genio pero que vive dentro de una botella" - Jorge Martinez -
 spellcaster Member #1,493 September 2001 Glad I could help.I had a similar problem some time ago... when I found the non diamond shaped version, my life got so easy --There are no stupid questions, but there are a lot of inquisitive idiots.
 DOAdal3t Member #2,067 March 2002 I'm dumb!... spellcaster shouldn't u know better...use the diamond-style, but use it different...(another way of drawing(really better for looping/wrapping tiles))sorry I give u the dignity to commup with the anwser...(it is much better than that odd/even stuff) so that were all the hints...[url http://home.wanadoo.nl/~mkmk/screen2%20copy.jpg]ps... sorry the new engine is ready soon...(so new screenshots) __________________This is MY world, Enter
 spellcaster Member #1,493 September 2001 Not sure what you want to tell me here?Main problem with diamond style is not drawing but screen->tile coords conversion.And writing a map editor is much more easy as well.But I'm always open to learn new things So, enlighten me... --There are no stupid questions, but there are a lot of inquisitive idiots.
 DOAdal3t Member #2,067 March 2002 gay... but I now own u(if it is something new to you).. well I now own all the people who read it:so bow for me, I am the elite...(still searching for others)well enough about that;D``` 0 1 3 2 4 6 5 7 8 ``` this is simpler isn't it... well it has more... __________________This is MY world, Enter
 spellcaster Member #1,493 September 2001 I still don't get it.What's the good thing drawing your tiles like this? All you did was drawing right->left instead left->right.IMO this adds one more step during the screen->map conversion process.Ok, so what do you gain if you draw your map this way? --There are no stupid questions, but there are a lot of inquisitive idiots.
 DOAdal3t Member #2,067 March 2002 I never need to worry about odd/even... so e.g. circles will be circles...8-) __________________This is MY world, Enter
 spellcaster Member #1,493 September 2001 Odd / even?Circles?I never had problems before with circles... If I place circle tile nest to each other in the editor, I have a nice circle on the map.And odd even is not really a problem. The most easy thing is to unroll the loop slightly and to draw both odd and even row in one iteration.Ok, guess i'm dumb, but:a) I don't understand the porblem you have with using a rect approachb) I'm not sure how your approach is better than the ´"normal" diamond shaped map wayHelp? --There are no stupid questions, but there are a lot of inquisitive idiots.
 DOAdal3t Member #2,067 March 2002 the algoritm to place the tiles(so that they overlap the good way) is fairly difficult in the other diamond way.In my way it is really straight forward...and about the circles... in my way it is really easy to change diameter without a set of precalculated masks(U use that... I think?).I think u should relook the numbers...;)(cya tomorrow(need to sleep)) __________________This is MY world, Enter
 spellcaster Member #1,493 September 2001 Sorry, but I think you want to solve a problem which doesn't exist ``` 0 4 1 7 5 3 8 6 9 ``` That's the "normal" way to draw diamond shaped maps, with (0,0) at the top, and map-x increasing down right, y increasing left-right.So, basically you switched the direction of x (or swapped x and y, depending how you view it).And i'd really like to know how you draw circles without having the tiles containg the circle gfx?I mean, circle with a diameter of 10 tiles needs other gfx then a circle with a diameter of 20 tiles...But the main problem with the diamond shaped map is the conversion from screen to map coords. --There are no stupid questions, but there are a lot of inquisitive idiots.
 DOAdal3t Member #2,067 March 2002 d00d, why did you not propose the "normal" way... Cos DanielH proposed:``` 0 1 2 3 4 5 6 7 8 9 A B C D E F ``` which is totally sick...and u only proposed the odd/even way...So I thought why doesn't anybody propose the way I use...(yes your normal way is abvious totally the same(so yes we were talking about no problem))But I still think that the "normal" way is better than the zigzaw way. take for instance the calculation of a guy on ht isometric tile-map... in the jigzaw-way u still need to worry about odd/even... and also for placement that is neccesary... as for the normal way... all is pretty straight forward... __________________This is MY world, Enter
 spellcaster Member #1,493 September 2001 Ok, assume you have a map drawn your way. Please tell me how do you translate a mouse pos into tile-coords?Assume that the "tip" of your diamond is not visible, how do you determine what to draw? Ie. which tiles are in the first visible row?Also, since you need to increase both x and y for each tile, you have more work in your inner drawing loop. At the end of a row you need to do additional work to reset the starting position.Finding the correct number of tiles to draw per map row is also a problem since the number of visible tiles per map row differs...Having multiple levels (along the z axis) does also become more complicated, esp. inside an editor.Quote: take for instance the calculation of a guy on ht isometric tile-map... in the jigzaw-way u still need to worry about odd/even Pardon? If the guy can move independently from the tile position (free movement) all I need are his world (screen) coords. Which can be translated to tile coords easily. But this is not needed, since you can do almost everything in screen coords (like sprite / sprite collision).If he's attached to tiles, all you need to do is to keep constant track of the tile he's currently on (so the tiles have an object pointer which points to whatever is on them, like the player, enemy an item, etc).So, in the worst case you need to convert screen to tile coords, which is almost as cheap as with normal rect maps. --There are no stupid questions, but there are a lot of inquisitive idiots.
 DanielH Member #934 January 2001 My map is like this ``` 0 4 1 8 5 2 C 9 6 3 D A 7 E B F ``` but I draw it in this order. That was a problem. ``` 0 1 2 3 4 5 6 7 8 9 A B C D E F ``` By determining which tiles go where and when, the drawing was easy. All I have to do is supply which tile is at pos 0. Then the map template program does all the work. Very easy very quick.I have varying size tiles, width and height. So I also check to see if any are inside the drawing area before trying to draw them. That saves time also.About the tiles, the bases are all the same. 64x32, but you can have anysize object. Just center it vertically in the tile and adjust it so that the bottom of the object is in the center of the tile.
 spellcaster Member #1,493 September 2001 Ok, since both of you use diamond shaped maps... if you have a map which is way larger than the screen, how do you guys determine the upper left tile? --There are no stupid questions, but there are a lot of inquisitive idiots.
 DOAdal3t Member #2,067 March 2002 d00ds... think....So I was right, u people don't get it(well at least danielH)...The drawing order IS:``` 0 4 1 8 5 2 C 9 6 3 D A 7 E B F ``` And just for the info... my tile-map=3000*3000 tiles(32*32 bitmaps see my screenshot), and it is wrapped(looping)and to spellcaster:the "guy" has a real xy, a screen xy and a tile xy which is simply calculated from the other two. __________________This is MY world, Enter
 1   2   3  Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads