0
votes

i want create road parallax scrolling down with flash in as3, when i run the script, the parallax moving up. and this my code

package {
import flash.display.MovieClip;
import flash.events.Event;

public class kelas extends MovieClip{

this i create variable

    public var road:road1;
    public var road2:road1;
    public var roadContainer:MovieClip;
    public var roadBreadth:Number;
    public var car:Car;

    public function kelas(){

and this create car , road and container

        car = new Car();
        road = new road1();
        road2 = new road1();
        roadBreadth = 653.7;

        car.y = 10.0;
        car.x = 10;
        road.y = 10.0;
        road.x = 10;
        road2.y = road.y + roadBreadth;
        road2.x = road.x;

        //* add child object
        roadContainer = new MovieClip();
        roadContainer.addChild(road);
        roadContainer.addChild(road2);
        this.addChild(roadContainer);

        this.addEventListener(Event.ENTER_FRAME, onEnterFrame);

public function onEnterFrame(event:Event):void
    {

        car.y = car.y + 15;
        roadContainer.y = 10 - car.y + 10;

        if (road.y + roadBreadth + roadContainer.y < 0)
        {
            road.y = road.y + (2 * roadBreadth);
        }
        if (road2.y + roadBreadth + roadContainer.y < 0)
        {
            road2.y = road2.y + (2 * roadBreadth);
        }
    }
}   

i want this backgroung moving down is not moving up, please help me

2
This line.. if (road.y + roadBreadth + roadContainer.y < 0) is most likely not doing what you think it is. Here it says if (10.0 + 653.7 + (-5) is smaller than ZERO) { then make road.y = 10 + (1307.4) }. What are you trying to achieve here exactly?? What object in your code is the background exactly? Is it road? or roadContainer?VC.One
Read this link scroll down to "Logical Operators" section to understand how to check thing-A AND thing-B using && or also thing-A OR thing-B using ||VC.One

2 Answers

0
votes

Have a look at this sample, it's a pretty simple idea to wrap an object around. Make sure your multiplier is set to the amount of roads that you're wrapping.

if (road.y > 600) {
    road.y -= road.y * 2;
} else {
    road.y++;
}
0
votes

may be your roadContainer contains road, so when you move roadContainer, you moves road too. so, just move don't let it contains, add when you move the background.y++, road will like moving up