2D Game Scrolling in AS3 (my very early implementation)
A few weeks ago I started work on a new game as a hobby project… unfortunately I also started playing A LOT of Company of Heroes on the PC, so progress on the programming has been slow, very, very slow.
But I did write at least one useful piece of code that I think some people might find useful: Level Scrolling.
When I was working on my first Flash 2D platform engine Sprocket (game was never finished). I found one of the biggest problems was having the level scroll properly. So this time when I started writing the game engine, scrolling was the first thing I nailed down.
In Sprocket I found that scrolling with the Character locked in the center of the screen was unsatisfactory as enemies could easily sneak up behind you. So I developed a system where the mouse controls the user’s view. I was inspired by the scrolling in PC games such as Abuse, and Soldat.
In my new game I’ve created a LevelDisplay class which handles all scrolling work automatically. Just tell the LevelDisplay what game sprite to focus on and it will handle the rest.
Keep in mind all of this code is very early, so please don’t just plonk this in your game. Once I’ve built an actual game I’ll have a better idea of how successful my implementation actually is. But for now I’ll share what I have and maybe you can get some use out of it.