Free ActionScript

Flash AS2 & AS3 Tutorials, Game Code, Effects, Source Files & Sample Downloads

Parallax Movement Effect

17 Comments »

This is a fla example of my parallax engine. Can be used in top-down space shooters or side scrollers with a little work (just remove the y movement from the code).

Preview

Download Fla Sample

Download Fla Sample

Update
AS3 version of this script is available here:
http://www.freeactionscript.com/2010/06/endless-starfield-parallax-scrolling/

17 Responses

Cool effect! Thanks.

  • unfortunately all examples are in AS2.Do you have AS3 versions of them ? Just a thought because of your site header…Flash AS2 & AS3 Game Tutorials, Samples, Source Files & Downloads.

  • The only changes I would have the images progressively get larger as they get more distant. so the img edges aren’t as visible in the furthest layer

  • John, I will be releasing AS3 versions of my examples soon. I am currently trying to make a full AS2 library, and then proceed to make those examples in AS3. Unfortunately AS2 is still very popular.

  • EightySeven, i added a simple “boundry” in to the example so a player wouldn’t leave the parallax field while playing around with it.

    Ideally, one should stop scrolling the lower fields(maps) when they reach the edge of the stage. In the current example, the scrolling stops when the field(map) reaches the player.

  • thanks for the move to AS3! looking forward to your migrated versions. your examples helped me a lot in shaping up my game :)

  • Very nice. I was a little disappointed when I saw that the star field was not dynamic, but nonetheless you did a marvelous job.

    Great site, by the way. I will be checking it regularly.

    - Noah

  • Hi NoahJ,
    It’s not dynamic to keep it as simple as possible. But I would like to make a dynamic parallax starfield effect.

    When you say dynamic, do you mean just an endless starfield?

    Thanks,
    PR

  • Hey, this is fantastic, and works even better if you set the stage to no scale and 100%. However, if you do this, you end up running off the screen.

    How would I go about making some edge detection, so that when I get to the far left, right, top or bottom, the space ship flies to the edge, instead of remaining in the middle of the screen and the starfield moving off behind it?

    Thanks

    Graeme

  • grayhammy; modify the edge detection code to move the player if the map is next to the edge.

  • That’s exactly what I figured, I am just not entirely sure how to detect the edges.

  • grayhammy; edge detection code is already in the example. That’s why the player stops when you reach the edge of the map. Look under //boundry

    If you find that code confusing, try making boundries work without the parallax effect first.

  • Oh yes, my apologies. As you say though, I want to check when the map is next to the edge, not when the player is. I will have a look, thank you.

  • Pradvan, I have added a simple trace to the Key listeners to check the _x value of map_mc, as this is the main boundary MC, and this reads out fine.

    However, if I try to use an if statement to check when the value of map_mc._x == 0 (for the left, and movieWidth for the right boundary), in order to then stop the movement of the parallax layers, and move the ship instead, it just doesn’t pick up when it hits…

    if(path.map_mc._x == 0) {
    trace("============ HIT ===========");
    }

    Is this because the multiplier for the movement is skipping over 0, in which case I will need to check a range around 0 or something?

  • map._x is almost never going to equal to 0. That’s why you should use the < = (less than or equals to) or >= (more than or equals to) operators.

  • How do I get this into a new actionscript file?
    I am going to make a vertical shooter, but when I open a new flash file, paste the code in there, and press control+enter, it just shows a blank screen on the preview.

  • Copy everything over from the library as well.

  • Leave a Reply

    You must be logged in to post a comment.