Path: chuka.playstation.co.uk!news From: Phil Gooch Newsgroups: scee.yaroze.programming.2d_graphics Subject: Different approaches to scrolling a tiled background Date: Mon, 07 Sep 1998 14:16:21 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 54 Message-ID: <35F3DCA5.3D5ADA21@easynet.co.uk> NNTP-Posting-Host: 193.131.140.246 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.05 [en] (Win95; I) I was just wondering how people handle the scrolling of a tiled background, say for a 2-d driving game. What I have done is break my array into sections, and then have an array of pointers to different sections, rather than have a huge array containing all the map data, avoiding all the duplications that would ensue. E.g. say I have: char road01[][NUM_COLS] = {'1', '2', '0'...... ... } char road02[]NUM_COLS] = {'4', '1', '0'... ... } So I can then do char *mapData = {&road01[0][0], &road01[0][0], &road01[0][0], &road02[0][0], &road02[0][0], &road02[0][0]. &road01[0][0].....} This allows me to repeat sections lots of times without having to repeat the data in the array, and also, depending on how the sections join up, have a random map that is generated for each game, where the section data is constant but the order, combination and number of sections can be random. However, this makes the scrolling algorithm tricky because you need to work out which section you need to display as well as which row of the section's array. At any one time you could be displaying (allowing for two offscreen rows, one just off the screen at the top, and one just off the screen at the bottom) data from up to 3 sections at once. I've solved this though, but what is causing me a bit of grief is collision detection, because at any instant I need to be able to convert a sprite's screen coordinate (whether it is on-screen or way off-screen) into a mapData coordinate that tells me which section it is on as well as which row and column of the section, all while the screen is being scrolled up or down. So this approach has some advantages but, for me, quite raises quite a few programming problems. So, how do other people handle large array data sets for scrolling worlds? Should I ditch my memory-efficient approach and just repeat the data in one large array so I only need to worry about rows and columns, or is there another way? Cheers Phil