Results 1 to 20 of 25
Thread: JAVA storing objects
- 02-23-2012, 10:41 PM #1
-
Re: JAVA storing objects
No, a database is much better for this by far. Much better.
- 02-23-2012, 11:13 PM #3
Re: JAVA storing objects
My problem is that i want to be able to save "maps" for my game and one map is 1000x1000 tile objects + extra objects inside .... and these maps should be loaded at the start up of the game so I have to figure out a space efficient way to store them so they can be "stored with the game" and recreated at start up of the game ... Thanks for your time =)
-
Re: JAVA storing objects
Assuming a map is made up of tiles, How many different tile types are there?
- 02-23-2012, 11:38 PM #5
Re: JAVA storing objects
The objects are all the same ... the only thing that differs is the information. Ex points to different images , contains a sub object eg. a flower, stone ... etc
ideas?
-
Re: JAVA storing objects
First off, I'm no expert in any of this, and so am only giving thoughts, not advice, but having said that, if the tiles were of limited type, i.e., grass, forest, rock, water, then you could store the map as an array of ints or something similar. If they can hold objects and only a minimum of them hold objects, then a sparse array (using collections) of some type could work. If all is complex then a database, and why not, since Java works quite well with databases.
- 02-24-2012, 12:04 AM #7
Re: JAVA storing objects
The problem is they all have different attribues ... like walkable (boolean) ...spawn point (boolean) ... Im not sure how much information they need to have because i'm in a very early stage of the game ... By database do you mean mysql? because my goal is for this game to become an applet. (Currently working on a mapeditor to create the maps for the real game)
- 02-24-2012, 01:20 AM #8
Re: JAVA storing objects
Check out ObjectDB. It's a commercial product, but their licensing terms are pretty lenient for educational or even small commercial projects. I think you can have up to 10 JPA @Entity classes and (presumably) unlimited @Embeddable classes with the free license.
Get in the habit of using standard Java naming conventions!
-
Re: JAVA storing objects
Another option is the Derby DB which is now part of Java and is free. It may now be called Java DB or something similar.
- 02-24-2012, 07:25 AM #10
Re: JAVA storing objects
Thank you guys ... I'm still trying to figure out the best approach and your ideas are very helpful. If i would take the database approach ... how would that work with an applet. The server holds the database and the applet loads from it? Thanks again.
- 02-24-2012, 09:09 AM #11
Re: JAVA storing objects
I have no experience in the line, but search around for applet-servlet communication.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-24-2012, 09:52 AM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: JAVA storing objects
A lot of that sounds like something that belongs as general rules for the game.
You only need to save the things that are not general rules, or Thing attributes.
For example, it should be possible to recreate the 'walkable' flag simply from the type of terrain. Therefore there is no need to store that flag, just an id indicating the terrain type.
I suspect spawn points are different, so you'll probably want to store that.
Essentially pare it down to the minimum needed to allow the existing game structure to recreate the map, then see how big that is and then decide how would be best to store it.
Assuming a tile is not all that complex a handful of bytes would do, mostly flags.Please do not ask for code as refusal often offends.
- 02-24-2012, 11:23 AM #13
Re: JAVA storing objects
Thanks for the advice !
As it is now the "tile objects" only have one image the current background . But i want to be able to place stuff over it and then flatten it to one image ... ex each tile object contains an array of images first we have the background at [0] then if i want to place an object over it (ex a flower) then i place the flower in [1] and flatten the images to one image.
I'm starting to think that this is the wrong approach because if a have a tree for example then it would stretch over multiple tiles ... so maybe its better to have all objects (trees,stones,leafs) on a different coordinate system and draw them as separate objects having nothing to do with the tiles. This way I can move behind trees and in front of them ...
Anyway I checked gamedev.net and a lot of people there are using XML to store the maps ... Is that beneficial?
- 02-24-2012, 11:33 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: JAVA storing objects
But the tree is centred on a single square.
Think in terms of your squares, not images.
You do not want to store the actual image (there's no game I can think of that does that) for part of a map.
You want to store data that describes what is in that square.
This goes back to your other thread on drawing.
You have a background consisting of stuff that is underneath the stuff that moves...this probably include your flowers and rocks etc.
You then have stuff that effects how your characters appear, in other words things like trees.
IIRC older Settlers games would have two level trees, so the trunk and then the larger canopy.
The trunk hid people behind them (ie higher up the screen), and the canopy hid things underneath it's spread.Please do not ask for code as refusal often offends.
- 02-24-2012, 12:03 PM #15
Re: JAVA storing objects
But im thinking the advantages of having the objects on a coordinate system is that I can place them where ever I want (ex between 2 squares) . I'm not a good java programmer I just want to create a game for fun and basically your post is confusing for me. I'm not trying to store the image =P im trying to reference how to build it.
So you are saying that I should have 2 different types of objects? objects that will be painted (flatten) with the background, and objects that affect the game should also be kept inside and have a internal position inside the tile object? so first i paint everything that can be walked over ... then i draw the trees etc?
Sense I draw everything upside down and the "hero" is centered it will cover the hero if the hero is higher than the object .. (not including background) .. Thanks for you input =)
Do you think that the XML would be better than other ways to store the map?
- 02-24-2012, 12:20 PM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: JAVA storing objects
OK.
I see now.
It was the mention of tiles, which implies (in map work) essentially squares. The contents of the tile are often then defined in a Tile object, listing all the things in the tile itself. And that would be the thing that is saved.
Anyway, if it's not tiled, and you're just painting some stuff wherever as an overlay say in order to make things look less regular and tiled, then I don't really know.
The choice of how to save it will all depend on how you are building this thing. What it looks like, what it contains.
Going back to the tiled idea, say you pick XML (which isn't a bad choice, but can be bulky, though easy to read), you'd have an XML structure for the Map containing Tile entries in it for each of the Tiles, which contains the data for that Tile. Now if there is an overlay (ie things that are not part of a tile, but are painted onto the map) then that would be saved as a section after the Tiles, consisting of XY coordinates and what the thing is.
eg.
Note I have no idea what your game is or what your map has in it.Java Code:<Map> <Tile> ... tile data here or as attributes of Tile, up to you... </Tile> <Tile>...</Tile> etc <Overlay> <Thing> <Flower x=1 y=200/> </Thing> <Thing> <Pebble x=10 y=20/> </Thing> etc </Map>Please do not ask for code as refusal often offends.
- 02-24-2012, 01:44 PM #17
Re: JAVA storing objects
Well you are correct the game is "Tiled" . Basically then each tile object would contain a "list" of other objects and their offset within the tile? so when i draw the object i just draw everything that's in that list? This caused the cpu power to go from ~4 to ~10% =P
Thanks for your help =) I will research a bit more about the storing part..
- 02-24-2012, 01:56 PM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: JAVA storing objects
That's one way, but as I said I have no idea what you are doing beyond the most basic concept of a tiled map.
I'm thinking in terms of Settlers, Civ, that sort of thing (ie fairly basic maps).Please do not ask for code as refusal often offends.
- 02-24-2012, 02:05 PM #19
Re: JAVA storing objects
- 02-24-2012, 02:23 PM #20
Re: JAVA storing objects
The more I read your posts, the more I feel that you are mixing the game state -- the model -- and its visual representation -- the view. Try to achieve a separation of the two, even if you don't go for full MVC.
Then you only have to store the state, the model, which should be orders of magnitude smaller than storing the entire view + state. The view will walk the model and build itself.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Storing objects into an arraylist in a different class?
By tepichi09 in forum New To JavaReplies: 2Last Post: 11-06-2011, 07:19 PM -
repeatedly instantiating new objects and storing into an array.
By doranm09 in forum New To JavaReplies: 6Last Post: 11-02-2011, 03:38 AM -
Storing objects in an array list?
By Moedig in forum New To JavaReplies: 3Last Post: 10-27-2011, 06:39 PM -
Storing objects
By paul1024 in forum New To JavaReplies: 5Last Post: 04-30-2011, 06:12 AM -
Storing objects directly with db4o
By german in forum JDBCReplies: 0Last Post: 05-12-2009, 08:22 PM


5Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks