Jump to content
Search Community

Parallax Scroolling in actionscript 3

floatingwoo test
Moderator Tag

Recommended Posts

Hi , I'm just looking to have a basic background scrolling motion tied with the movement of the player in Flash using actionscript 3. Mountains in the background ,buildings  in the middle and grass in the foreground kind of stuff. The player would be moving horizontally to mouse clicks. I found a post here in the forum but it was for JavaScript . Can someone point me in the right direction for getting more info on using TweenMax for doing this. Sorry about the misspell .Thanks

Link to comment
Share on other sites

In the most basic terms you just want to move each element at different speeds

 

function movePlayerRight(e:MouseEvent):void {
   TweenMax.to(bushes, 1, {x:"-=100"}) 
   TweenMax.to(buildings, 1, {x:"-=70"}) 
   TweenMax.to(mountains, 1, {x:"-=30"}) 
}

I'm really not sure how you plan to implement your player movement. A lot of work can go into creating a robust parallax effect. Here is a great tutorial which covers a lot of the nitty-gritty about getting each scrolling element to loop indefinitely

http://active.tutsplus.com/tutorials/games/add-depth-to-your-game-with-parallax-scrolling/

 

Link to comment
Share on other sites

Ok , Heres an example thats about as basic as it gets. This has the background layers reacting to the position of the mouse. So it wouldn't be to much of a jump to have them listen for a mouse click by changing (MouseEvent.CLICK). And having the character moving to the same Event. Am I on the right track?

 

 

import com.greensock.TweenNano;

import com.greensock.easing.*;

 

//ease type

var easeType = Expo.easeOut;

//xmouse will hold x position of the mouse in relation to the center of the stage.

//assuming that the stage center's value is 0;

var xmouse:Number = 0;

// percentage of the xmouse position

var xPct:Number = 0;

// speed or durationl

var speed:Number = 14;

 

// add event listener based on mouse movement

stage.addEventListener(MouseEvent.MOUSE_MOVE, render);

 

function render(e:MouseEvent):void

{

    //if xmouse pos is greater than the center of the stage

    if( e.stageX > stage.stageWidth/2) {

 

        xmouse= -(e.stageX -stage.stageWidth) - stage.stageWidth/2; //-512

 

    }

    else

    {

        xmouse = ((stage.stageWidth/2) - e.stageX); //512

 

    }

 

    xPct = Math.round ((xmouse/stage.stageWidth) * 200);

 

    //where will the sky moveclip move to...

    var skyXto:Number = ((xPct/100) * (sky_mc.width - stage.stageWidth)/2) + stage.stageWidth/2;

 

    TweenNano.to(sky_mc,speed, {x:skyXto, ease:easeType});

 

    var fieldXto:Number = ((xPct/100) * (field_mc.width - stage.stageWidth)/2) + stage.stageWidth/2;

 

    TweenNano.to(field_mc,speed, {x:fieldXto, ease:easeType});

 

    var grassXto:Number = ((xPct/100) * (grass_mc.width - stage.stageWidth)/2) + stage.stageWidth/2;

 

    TweenNano.to(grass_mc,speed, {x:grassXto, ease:easeType});

 

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...