Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Tile Management  (Read 1502 times)
0 Members and 1 Guest are viewing this topic.
Offline iamtommo

Senior Newbie





« Posted 2012-06-15 15:17:45 »

Hey, i'm in the early process of writing a side-scrolling tile based game, and i have been trying to figure out which is the best way of caching tiles.

Idea 1:
I would store an instance of a tile class such as grass for every tile in the game (sounds very costly), this allows each tile to have its own unique properties (still being a subset of grass ofcourse).

Idea 2:
I would store the id of every tile in the game, and use a tile lookup table to retrieve a singleton instance of that tile, this option seems to be more fitting however then each tile of the same type must be the same globally, and couldn't have different properties to other grass tiles.

Which idea would be the most viable, and if you have a better idea, please feel free to share it Smiley.
Offline UprightPath
« Reply #1 - Posted 2012-06-15 15:49:05 »

Combo breaker!

Bad joke. Really, what you should do is something close to a combination of the two. If you know that there will be some set of values that will always be the same for a given tile type, regardless of location, etc. You store that data in a singleton-holding data structure. Or, I mean you could use an enum, which for semi-small numbers of types works like a charm and pretty much removes the need for you to do that. Hah.

Then, you pass that enum object to the Tile on creation, so that it has access to the TileType which stores all of its general data, without having to make a copy of it.
1  
2  
3  
4  
public enum TileType {
    GRASS, DIRT, ETC;
    //Fill in data that is the same for -all- types of grass.
}

1  
2  
3  
4  
5  
6  
7  
public class Tile {
    private TileType type;
    //Tile specific data.
    public Tile(TileType type, ... ) {
        this.type = type;
    }
}

If you don't think an Enum will cut it, try making a Factory of some sort instead.

Pass reference, not id. (Looking up this data could be costly, or not, but let your language do the work for you there.)

Offline iamtommo

Senior Newbie





« Reply #2 - Posted 2012-06-15 15:54:36 »

that idea of having a tiletype and each tile having a reference to a tiletype is EXACTLY how i have it atm, named the same, exactly the same code and everything lmao. Thanks and I'll probably go from this and work out the kinks as they arrive but if anybody has any better ideas hit me up Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 65K
« Reply #3 - Posted 2012-06-15 15:56:34 »

Idea 3:
Default case is sharing of tile objects, but whenever needed, just create a new tile instance with private unique properties and assign it to your tile map. If needed, add a flag "shared" or something.

Idea 4:
No individual Java tile classes at all, but each slot of the tile map stores an integer tile class property where tile properties are set as single bits and are modified during runtime, like door-tile, open-door, closed-door, wall, etc.
(from my current game, not for OO-freaks)

Offline iamtommo

Senior Newbie





« Reply #4 - Posted 2012-06-15 16:00:12 »

idea 3 is sort of what i'm working off now, and idea 4 could work for some primitive tiles but i'm looking for a bit more functionality, e.g. tiles will interact with the player.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (60 views)
2014-12-09 22:41:13

BurntPizza (95 views)
2014-12-08 04:46:31

JscottyBieshaar (55 views)
2014-12-05 12:39:02

SHC (71 views)
2014-12-03 16:27:13

CopyableCougar4 (73 views)
2014-11-29 21:32:03

toopeicgaming1999 (133 views)
2014-11-26 15:22:04

toopeicgaming1999 (124 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!