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
if (road.y + roadBreadth + roadContainer.y < 0)
is most likely not doing what you think it is. Here it saysif (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&&
or also thing-A OR thing-B using||
– VC.One