Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
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 2212 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.
public enum TileType {
    //Fill in data that is the same for -all- types of grass.

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)

Lethal Running - a RPG about a deadly game show held in a futuristic dysoptian society.
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.

Archive (172 views)
2017-02-27 19:41:49

numerical (515 views)
2017-02-21 07:32:16

numerical (517 views)
2017-02-21 07:31:46

theagentd (630 views)
2017-02-18 13:42:33

theagentd (624 views)
2017-02-18 13:35:16

h.pernpeintner (1797 views)
2017-01-24 22:39:11

h.pernpeintner (1738 views)
2017-01-24 22:38:32

Galdo (2304 views)
2017-01-12 13:44:09

Archive (2193 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2725 views)
2016-12-16 03:58:39
SF/X Libraries
by philfrei
2017-03-01 20:21:46

SF/X Libraries
by philfrei
2017-03-01 20:21:24

SF/X Libraries
by philfrei
2017-03-01 20:17:31

SF/X Libraries
by philfrei
2017-03-01 20:16:43

SF/X Libraries
by philfrei
2017-03-01 20:15:36

SF/X Libraries
by philfrei
2017-03-01 20:14:20

SF/X Libraries
by philfrei
2017-03-01 20:12:46

List of Learning Resources
by elect
2016-09-09 09:47:55 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!