Tilemap sectionload

Started by
1 comment, last by pyro sauce 12 years, 3 months ago
Okay, so i made this map loader that only loads the tiles that are being drawn on screen,but i made it kinda bad. Basically it reads a file and does something like
Scanner in = new Scanner(file);
for(int i=0; i<mapAry.length && in.hasNextLine();i++){
if(i<Main.yShift) in.nextLine();
Else{
for(int n=0;n<mapAry.legth&& in.hasNext();n++){
if(n<Main.xShift) in.next();
Else mapAry[n] = in.next;
}
}


And every time the playermoves over enough it ajusts xshift accordingly along with forcing the player back 32 px(aka 1 tile)

The whole map loading is choppy but thats not the main problem i came to ask about.
The problemis how do I get npcs to spawn with this? I was thinking of using xshift again to adjust the npc position on spawnbut how do i get them to spawwn only if they would be onscreen and also make sure theydont walk off screen or into ground tiles?

Oh and my npcs currently spawn from a txtfile; each line is an npc and its x y id atthe moment, but idk what im gonaa do with npc id cause theres only 1 Npc class so its not like i can make different npcs...
Advertisement
How big a world you are going to make? I am doubting that such a data streaming mechanism is a bit of over kill for tile based game, unless the world is huge or you are working in a restricted environment (such as low memory etc).

Otherwise, to improve your streaming, you should perhaps load bigger chunks instead of just a screen full of tiles. You could for example split your map to 256x256 (you can choose any number) blocks and keep 9 of these blocks in the memory all the time (the current block and the 8 surrounding blocks).

With the NPC's, you can spawn the NPC's that exist in the 9 blocks area. If you move too far away from the NPC's, you may freeze them until needed again or delete them. The question is of course how many NPC's your world has and do they need to keep some certain state. What I mean by this is that if you kill an NPC and you leave and come back again the NPC is respawn again.

Anyway, are you working on a phone or some other device with limitations?

Cheers!

How big a world you are going to make? I am doubting that such a data streaming mechanism is a bit of over kill for tile based game, unless the world is huge or you are working in a restricted environment (such as low memory etc).

Otherwise, to improve your streaming, you should perhaps load bigger chunks instead of just a screen full of tiles. You could for example split your map to 256x256 (you can choose any number) blocks and keep 9 of these blocks in the memory all the time (the current block and the 8 surrounding blocks).

With the NPC's, you can spawn the NPC's that exist in the 9 blocks area. If you move too far away from the NPC's, you may freeze them until needed again or delete them. The question is of course how many NPC's your world has and do they need to keep some certain state. What I mean by this is that if you kill an NPC and you leave and come back again the NPC is respawn again.

Anyway, are you working on a phone or some other device with limitations?

Cheers!


Well I have to present it on vista, does that count?

heeehee, but in all honesty the only real reason i did it was because that's how it ended up being. I originally had taken the time during calculus to write myself some notes and stuff on how I would have everything work, but my notes weren't really as descriptive as they normally are because I was writing them with my left hand while taking notes on integrals with my right, so when I got home I had some trouble remembering exactly what i meant and I just kinda ended up with some spaghetti and glue...

I suppose I should probably take the time to figure it out again and re-write everything (because everything else is kinda based on that) but before I do that I should ask some questions...
(I hope I'm not getting off my own topic here... if I am just let me know)
First off, I've always done something like this
class main extends applet implements KeyListener{...}

but lately I've noticed that everyone seems to make a JFrame and do something with java.awt.Canvas. Is that way better?
also, should I have more classes than just Main, NPC, Player, LoadMap? I've noticed that people often have an Entity class.. why is this exactly? does it make it easier to do something specific or is it just common ways?

Basically, is there any common ways or convention to making a game? some kind of guideline that I can follow so that I know that I'm not doing something completely wrong.

This topic is closed to new replies.

Advertisement