-
Generating A Map
Im making a racing game, and the map is tile based, but the tiles are 1 screen size and get placed 1 after the other. There are no real corner just curvy bits in the tiles that you fly threw.
I can generate a map place all the tiles on screen, scroll them, do preaty much every i need, but i cant think of a good way of only displaying the tile your on and the tile before and after that one.
How could it be done? My maps are about 400 tiles so around about 200k pixles long at most so it would be a bad idea to run a loop to find what tile my ship was on. My whole map is placed into a blank MC. And my mapdata is stored into an array, although its not used for anything and the tile refrances are stored into an array and thats what i used for running collisions.
Any one have an idea?
-
I'm not sure I understand correctly. Are you saying you have tiles that are as big as the screen? Wouldn't it be easier to have smaller tiles so you can reuse smaller parts easily?
But to answer your question : if you divide the "camera"'s position by the screen size (and drop the decimal numbers), you know which segment you are on. If you have a seperate multideminsional array with information which tiles are in which segment, you can reduce the for loop a lot.
Note, in your case the segments will only contain one tile.
I suggest you read Strille's supertile tutorial. Even if you're not using supertiles, his methods of calculating which tiles need to be added when are very good.
[quote $and the tile before and after that one[/quote]
If your tiles are as big as the screen, and you're only scrolling in one direction, you only need two tiles at the most on screen, so only the tile the camera's top left corner is in, and the tile next to that. If you scroll in two directions, you'll need four tiles visible on screen.
-
Oh yeah, so i only need 2 tiles then, i could use smaller tiles but that would require me to create a more powerfull engine to orgaize my tiles and select the correct ones. Its hard to explain but the main thing is that i understand.
I sorta understand your idea, ill go have a play.
Cheers