   2D scroll with directX 9
  Hi all,I would like to make a 2D RTS with a tile based map. I want to add a smooth pixel scroll to it but I don't know which method is the best, knowing that all my tiles are stored in an offscreen surface :1/ rebuild all the background to the backbuffer (tile by tile) each time the user scroll in any direction, translating the map origine point from N pixels2/ build the map in an offscreen surface slightly larger than the screen (with extra rows and columns of tiles) then copy a rect with the size ot the screen from that surface to the back buffer.3/ build the map in the back buffer with extra rows and column and moving a camera  or viewport from N pixels. I don't know if this method is possible.I hope I was clear.Has anyone an idea?   
Quote:Original post by benzoHi all,I would like to make a 2D RTS with a tile based map. I want to add a smooth pixel scroll to it but I don't know which method is the best, knowing that all my tiles are stored in an offscreen surface :1/ rebuild all the background to the backbuffer (tile by tile) each time the user scroll in any direction, translating the map origine point from N pixels2/ build the map in an offscreen surface slightly larger than the screen (with extra rows and columns of tiles) then copy a rect with the size ot the screen from that surface to the back buffer.3/ build the map in the back buffer with extra rows and column and moving a camera  or viewport from N pixels. I don't know if this method is possible.I hope I was clear.Has anyone an idea?I've tried pretty much all of the above and in the end opted to create an array of tiles for the given scene inclusive of additional edge tiles that our not visible. i.e. 1 for each edge, top, left, bottom, right. These tiles are loaded into a VertexBuffer when required and rendered each frame. During movement I simply move the camera, when the last edge tile is visible I reload the array of map tiles with a new offset/starting positions. Although you could probably optimise further by only updating textures within the VB etc and resetting the camera position the small number of tiles created when a full tile width scroll occurs is so small it doesn't hurt performance at all. I chose this method as opposed to a huge vertexbuffer with my entire scene because my scenes are very dynamic with tile textures changing frequently. Again, though with todays hardware you could probably get away with simply creating a massive VB anyway and simply lock and update texture coordinates. Anyway, I just opted for to go the small vb route as the number of tiles per scene is pathetically small.BTW, if you are thinking of incorporating lighting/shadows you may well want to skip the idea of tiles all together as meshes will be your friend!:);  Yeah, have an array showing the current tiles which are in the view, then on key press move this array a certain amount. From there it shouldnt be too hard to render it - if you need help with that reply her. The book "Teach Yourself Game Programming With DirectX in 21 Days"by Sams Publishing / Clayton Walnum shows how to do this in depth   ;  You can find a sample of how to do this with the "Simple 2D" sample in the DirectX Sample Browser.;  thank you for your answers.Quote:Original post by SeikoDuring movement I simply move the camera ...I'm not an expert in d3d, is the camera a directX notion or simply a pair of variables representing the screen origin inside the global map?   ;Quote:Original post by benzothank you for your answers.Quote:Original post by SeikoDuring movement I simply move the camera ...I'm not an expert in d3d, is the camera a directX notion or simply a pair of variables representing the screen origin inside the global map?I'd check out the example mentioned above and pay close attention to the world, view and projection transform code. This is basically the concept of a camera. BTW, I'm no expert either and to be honest I jumped into D3D at the same location as yourself which is unfortunately what I now consider the wrong end. I chose to go the tiling route but paid little attention to core concepts of world, view and projection transforms. These elements are absolutely fundamental and although you can get by with a little knowledge in terms of tiling approaches and a 2d scroller you'll really want to get a complete understanding if you want to expand later on. I'm now struggling with shadows because I didn't spend enough time on the transforms/matrices. Ah well, it's all good fun and although frustrating it does come together eventually.:);  thank you very much for your help seiko!   