Results 1 to 2 of 2
- 08-11-2011, 06:49 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 19
- Rep Power
- 0
2D tilemap from 1d array blowing my mind!
Hello folks!
I've been facing problem with tile map for a while, for some reason i'd like to store all the tile map data on one file containing all the tile info in format as given in example
and then store all that in 1D array only knowing the regions width at the first, in this example it would be 2 so we could get 4 regionsJava Code:0011 1100 1010 0101
,Java Code:00 11
,Java Code:11 00
andJava Code:10 01
okay, i have no problem loading the 1d array into memory but when it comes to divide that 1d array in pieces of map called regions I can't figure out the best way nor any other way as long as i don't hardcode it.. :/Java Code:10 01
okay, lets see whats my ideas for this!
theres amount of tiles in each region stored into memory (this example case 2) then i have method that returns 2d int array containing all the tiles taking regionX and regionY ints as params
the program starts figuring out the starting place(x and y) from the 1d array to the 2d array like this
int startPos = regionX*regionWidth*regionY
okay, we now know the start position is 0 if regionX is 0 and regionWidth is 0 and regionY, the first problem here is that i want it work just smooth even if regionY was 0 and X 1 but when it *'s the number with 0 it becomes zero, i've tried something like
(regionX>0?regionX:1) but it will just mess all up i know! thats the first problem i want solved!
but even if the both regions were like 1 and 1 the starting position would be
1*2*1 assuming that regions width is 2, the answer would be 2
below i marked it with x
okay, we know now where to start from, looking good! now we only need to know where the looping should end at.. should be easy, but cant figure this out, i thought adding a square would help me out but it would only be like this..Java Code:00x1 1100 1010 0101
how can this be so hard? or is this the worst way to handle tilemap in regions human can think of? i just want efficient way that stores the tiles in regions from 1d array thats generated by map editor in same form, or do i really have to generate new file for each region? :SJava Code:00x1 1o00 1010 0101
please help me out with this, i can't really find anything on internet about tilemaps as regions or anything :(
- 08-11-2011, 07:55 PM #2
Similar Threads
-
Display Array on another class after extracting from txt file and into array problem
By jonathan920 in forum NetBeansReplies: 0Last Post: 05-12-2011, 07:04 PM -
Would you mind examining one of my programs and letting me know what you think.
By AcousticBruce in forum New To JavaReplies: 8Last Post: 12-20-2010, 08:03 PM -
some error make me mind
By andyzju in forum New To JavaReplies: 0Last Post: 11-20-2010, 03:22 AM -
Beginner - can't get through, mind looking at code and errors?
By hayden06f4i in forum New To JavaReplies: 8Last Post: 11-05-2010, 01:52 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks