Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Efficiency with tiled maps  (Read 931 times)
0 Members and 2 Guests are viewing this topic.
Offline jammas615

Jr. Member
**

Posts: 70



« on: 2011-12-28 00:16:33 »

 Just curious,
Is having a tile class which controls what it renders and an instance of that class for EVERY tile bad design.
Is there a better way?

Online Mads

JGO Ninja
***

Posts: 674
Medals: 16


Directly directional


« Reply #1 on: 2011-12-28 00:26:59 »

If you're storing a picture of the tile on every object, when most of them are similar, you could just give it a stamp and retrieve the image corresponding to that stamp when drawing.

Offline ra4king

JGO Kernel
*****

Posts: 3153
Medals: 196


I'm the King!


« Reply #2 on: 2011-12-28 00:28:46 »

That's the best and easiest design if you want each tile to control its own data. This way you could also take advantage of polymorphism and have subclasses of Tile that have specialized features.

Games published by our own members! Go get 'em!
Offline jammas615

Jr. Member
**

Posts: 70



« Reply #3 on: 2011-12-28 03:02:43 »

But memory-wise it would get ridiculous if you had massive maps all loaded at once, which could he solved by loading tiles as you need them, but would that slow things down?

Offline tw0v

JGO n00b
*

Posts: 14



« Reply #4 on: 2011-12-28 03:05:50 »

not if it's a small-scale project.

edit: you could just load the images from a map class while each tile references that object, saves a lot of memory.

Programming for better games.
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #5 on: 2011-12-28 03:48:56 »

not if it's a small-scale project.

edit: you could just load the images from a map class while each tile references that object, saves a lot of memory.
Assuming there is no per-tile data, yes.

There is no god.
Offline ReBirth

JGO Wizard
****

Posts: 1272
Medals: 19



« Reply #6 on: 2011-12-28 07:52:47 »

Sometime people store data per tile like what item on that tile or effect of a tile to character.

Offline sproingie

JGO Strike Force
***

Posts: 894
Medals: 55



« Reply #7 on: 2011-12-28 21:23:08 »

I've been playing with various tile engine designs, and I've settled on Tiles being simple immutable value objects, just an index into a Tileset, which both holds the TileTexture and maps names to Tile instances (the TileTexture is basically a spritesheet that the tile is indexing).  A Tile can also contain color information if I want to override the color on any specific tile, but otherwise it's a simple lightweight affair.  

All the actual opengl drawing commands are issued by a DisplayLayer, which contains a Tileset and a list of tiles.  This keeps the drawing code in one place, which makes it easier to optimize.  DisplayLayers can also contribute other things like a default color and blend mode, which makes stuff like moving a semi-transparent cursor around a simple matter of making a UI display layer I can enable and disable.

Tiles are strictly graphical in purpose for me, they don't contain game information, so I maintain separate 2d arrays for the game state, and just define a function to render a region of that gamestate array onto a tile display.
 
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.079 seconds with 19 queries.