Parallax Background

GingerBGamesGingerBGames Member Posts: 390
edited November -1 in Working with GS (Mac)
Hello GS'ers,

I was wondering if anyone had a demo or template out there that showed how to create a parallax background? What I'm trying to do is to have a chopper take and land, the background doesn't move. When it fly's up, then the camera follows him, when he moves left or right then the screen follows accordingly. I cannot figure out how to accomplish this for anything. Gr,r,r,r,r,r the frustration. Any how, if someone can shine a light on this with me, I would be very appreciated, thank you.

Comments

  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    Click the scene button, and on the left, select layers tab. Have the background on it's own layer and uncheck the "scrollable" box.

    Oh wait, I see what you are saying now. That sounds like a camera adjustment. Have the camera opened all the way vertically, and close it for horizontal.
  • heathccheathcc Member Posts: 113
    I don't know the thread link offhand, but if you search for Parallax you will find links to examples with some downloadable ones.

    The following is a really cool one (not downloadable, others are)- http://gamesalad.com/game/play/33976

    H
  • simo103simo103 Member, PRO Posts: 1,331
    in GS search 'third' I think it is Orbz's template of paralax and moving actors
  • GingerBGamesGingerBGames Member Posts: 390
    Thank everyone.
  • forkliftforklift Member Posts: 386
    SlickZero said:
    Click the scene button, and on the left, select layers tab. Have the background on it's own layer and uncheck the "scrollable" box.

    Once you wrap your head around parallax scrolling, it's really easy to accomplish.
    Here's my theory on it:

    Do the quoted above for each layer of parallax and have a game level attribute (i'll call it game.helispeed) track your helicopter's speed.
    When your helicopter is moving X direction, have the layers of parallax move the opposite direction by game.helispeed. The further back you go in your layers, the movement of the parallax will weaken. Usually I show this by:

    Parallax layer 1 = game.helispeed
    Parallax layer 2 = game.helispeed/2
    Parallax layer 3 = game.helispeed/4
    Parallax layer 4 = game.helispeed/6

    etc.. etc.. Adjust the divided by number to what feels right for your game as long as the further back the layers go, it's going slower.

    To make the background keep traveling (wrap around the screen) simply tell the objects in the parallax layers to reset their X position to the other side of the scene when they're off the screen by a distance of at least half their width.

    For instance, when you're traveling right, the layer is moving left. The object (a tree) is moving left and is 300 pixels wide total. When it is off the screen at least half it's width (150 - i'm going to say (self.positionX - camera.origin.X < -160) just to make sure it's completely off-screen), change it's X position to the opposite side of the screen (camera.origin.X + screen size + 160).

    Constrain the Parallax layers' height (Y value) to itself (where you placed it), so that it doesn't follow the camera if your helicopter moves upward.

    hopefully that will get you thinking more on how it is handled.
Sign In or Register to comment.