Skip to content


AS3 2D Tilescroller

click meclick me.

During the port of my AS2 classes into AS3, i thought i might take a stab at a tile scrolling engine. I never got into making one before, and since I’ve been delving into the magic that is BitmapData, i decided to give it stab. I need to do a little house cleaning, but i plan to throw up the code here soon…

In previous versions of Actionscript it was common to do variations of ‘move and replace’ based on movieclip positions and key strokes ( see TonyPa, Strille, Outside of Society, André Michelle, etc ). There was some great implementations and they worked well, but i figured with BitmapData it could be boiled down to a smoother and less intensive process – kind of what Keith has been labbing with.

What’s going on-
The layers ( there are 3 in the example but you can add however many before your graphics card yells at you ) are just a grid of Bitmap objects – the amount based on the ‘visable’ area divided by the tile size of the graphics.
They don’t move at all – instead they are offscreen and are updated based on the characters ‘x’ and ‘y’ velocity divided by tile size, of which its remainders are parameters supplied to the scroll method of a BitmapData instance that is redawing the layers upon key press.

In the coming days, i hope to strip out a little code and throw the source ( and maybe some drawings that will clear up my terrible explanation ) up here… just wanted to do a quick post for proof of concept.

Posted in AS3, Flash.


12 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Ash says

    Awesome :) I particularly like the parallax scrolling.

  2. Paul Neave says

    Nice one, can’t wait to see what you come up with!

  3. Josh Tynjala says

    If you run at one of the blocks, and then you turn and try to run the other way just as you are about to hit it, you will slide into the block and get stuck inside it for a short time.

  4. todd anderson says

    Hey Josh.

    yeah. i didn’t really debug the collision detection, was focusing more on the scrolling.
    Ash actually prefers getting stuck in the block as opposed to scrolling, so i’d feel bad if i fixed it :)

  5. Josh Tynjala says

    I forgot to mention that I like it ;)

    I’ve been stirring around the idea of building a side-scroller framework in Flash for some time. I made one a few years ago with C++ and DirectDraw for a Mario clone, and it was a ton of fun to build. It was also my first major OOP project. I learned so much about pointers and stuff like that. It basically got me through many of the important concepts in college.

  6. todd anderson says

    thanks, Josh. :)

    I don’t do much work in C++, but it is my main reading of late on the train ride home. A couple weeks ago something finally clicked about pointers ( which i had tried to get my head around when i first came across them about a year ago ) – be cool to see your implementation.

  7. Jay says

    This is very cool and quick. Yeah it does get stuck but you can make it jump out.

    Will you be posting files when you are finished?

  8. todd anderson says

    Thanks, Jay.

    I’m currently cleaning up the files and stripping some things out…

    Hope to have them up early next week.

  9. Ramses says

    Hey man,

    this looks awesome !!.. any chance to get the code :-p ?

    tnx

  10. nux says

    Excellent work !

    So smooth, and the parallax scrolling is great.

  11. Fredrik says

    looks great! …any chance of seeing the code for this ;o)

  12. Fredrik says

    haha and 2 seconds later he finds it :o P sorry for flooding…and thanx!!



Some HTML is OK

or, reply to this post via trackback.