Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D map in 3D optimizations  (Read 3540 times)
0 Members and 1 Guest are viewing this topic.
Offline led

Senior Newbie


« Posted 2004-04-08 14:18:33 »

Hi all, I can see a lot of new game based on 2D map (ie: all the rts new games). Anyway, though they might use terrain, I was wondering about ways to optimize without terrain.

So if some has some link to some optimized algorythm of a (x,y) map. Sure I thought of showing only some tiles depending on where the camera was, but still, there must be other ways.

thanks a lot.
Offline Planner1

Senior Newbie

« Reply #1 - Posted 2004-04-08 14:55:50 »

This is a very general question and so I'm sorry if my response too is general. Any space partitioning algorithm that works for 3D should have an equivalent in 2D. For example, you could use a quadtree to partition your map into smaller and smaller subsections and then display visible one's based on view. If you're using Xith, some of this stuff should be taken care of for you.
Offline led

Senior Newbie


« Reply #2 - Posted 2004-04-08 17:10:16 »

Ok, let me explain this with an example (oh and by the way the "zone" partitionning is a good idea!)

What I want to do is a terrain like my subdivided with tiles. Let's define what a tile is:

A tile is a square subdivided into small triangle making little square. So, a tile has about 10x10 small pane into it. So, that's about 200 polys (triangle). I can modify the poly coords to make terrain effects in it. A tile is also as large as a character in the screen, so it is not big like a terrain.

Now, let's define map:

A map is made of tiles aligned to each other (with the height of each tiles) Making the map like a Warcraft 3 map. A map can have 64x64, 128x128, 100x50, etc. tiles. Though, I'm just showing what the camera is seeing, let's say the camera is pointing the character like warcraft. So, I just want to show maybe 16x16 tiles.

Well, now that's where the problem lies. The basic way to do this is surely a 2D array, containing the tiles informations.

  • [y]

    and then getting the character position in the map, x and y, and limiting the vue to x + 8, x - 8, y + 8, y - 8.

    now you can loop with 2 for loops like this:

    for ( int y = charY - 8; y < charY + 8; y++ )
     for ( int x = charX - 8; x < charX + 8; x++ )
       if (we're not outside the array && the tile isn't null )
         enable( tile
  • [y] );

    ok, it can be a bit long, I thought of another way that is making an array with one dimension like this:

    tile[x * y]

    // getting the top left 16x16 square depending on the character position
    topleftSquare = ( mapSizeX * charY ) + charX;

    // getting the bottom left 16x16 square depending on the character position
    bottomleftSquare = ( mapSizeX * charY ) + charX;

    for ( int i = topleftSquare; i < bottomleftSquare; i++ )
     enable( tile )

    I don't know if it's really faster, but anyway.

    Another way could be making different BranchGroup, called zone. And when I'm approching of one zone, I enable it. While this solution can be the fastest (perhaps) It can be a problem if I'm in a 40x40 tiles zone and I load up a 40x40 zone.

    Or, I could load the map, and divid it into small 16x16 tile not caring of what the map is made of (a "room" could be cut in a half) but the user will not see this, since 16x16 is as large as the screen view.

    Any thought is welcome, I'm a bit lost in all this
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline EvgeniyS

Junior Newbie

Java games rock!

« Reply #3 - Posted 2004-04-08 21:03:45 »

if u have relatively small map i think it doesnt matter how u find visible area. I mean ur way is good for small map - when u can store it in array. If u work with something really complex and large u just cant afford to store all tiles in array , so u have to use quadtree or BSP tree - as sad above. BSP tree  have better algorithm for finding visible area. but again - for 64x64 it really doesnt matter.
BTW 2dimention array and 1dimension array is same in binary representation , so it doesnt matter  what exactly u use Tongue
Pages: [1]
  ignore  |  Print  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (159 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!