PDA

View Full Version : How to better handle large levels in a sidescroller



shazzmoe
September 10th, 2008, 01:41 PM
I am looking at various ways to code a sidescrolling game. I personally prefer using the hit test points method of doing things and for small areas it has been working great for me. However I am now trying to make a larger level for my game and the "ground" that my player walks on is longer than the 3700 pixels i can go to the right of the stage.

To clarify what i mean by this, I have a ground MC that scrolls left and right as the player moves around on it. So in flash I'm building the ground MC and have now gone so far to the right that it will no longer allow me to build any further in that direction. I could probably come up with a way to load a new section once the player reaches that point, but that would be very tedious to make it seamlessly stream into the next part. So i was just wondering if there was a way to make a movie clip span a wider section in flash. If not I'll probably just break up the level into sections.

Lou
September 10th, 2008, 10:49 PM
There are quite a few ways that you can go about constructing the background for your platformer. You could try making it from tiles. Imagine that "0" is sky, "1" is ground, and "2" is a box or obsticle.

mapLayer1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0]
mapLayer2 = [0,0,0,2,0,0,0,0,2,0,0,2,0,2,0,0,0,0,0,0,0,2,0,0,0]
mapLayer3 = [1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1]

You can create your level from an array or matrix. Make a function that reads the array and places a tile corresponding to each number in the array. As your character travels across the landscape have your game engine add tiles one or two spaces ahead of the screen, or you could completely render the background ahead of time. You can also remove the tiles that your character has already walked by.

The tiles can be movieclips in themselves and you can have whatever complicated things inside of each tile. You can perform this by creating blank movieclips at certain locations and attaching movieclips from the library to them using .attachMovie(libraryName, instanceName, depth).

Your tiles could be as big as you want, you could even make them the same size as the stage!

I am only a novice actionscripter so if any other kirupians have greater ideas, (which im sure many do) please post.

shazzmoe
September 13th, 2008, 03:03 PM
thanks, that sounds like theway I'll probably end up doing it. The function sounds easy to write but i guess I'll find out if that's true in a few days when i try it.

therobot
September 14th, 2008, 04:46 PM
yeah, a misconception people have with using a tile based system is that they think they are limited to a very grid like, 8 bit feel. the map data could represent whatever you want tho, it's like a blank grid. in this case, you'd want to have each spot on the grid be a different portion of the map. this way, you can ensure you aren't calculating too much off screen junk.