At 8/27/15 03:27 PM, Etherblood wrote:
At 8/27/15 06:55 AM, cuteboy99 wrote:
what is the best way to loop a background through coding or frames?
A simple way would be to put a copy of your background besides your background.
You can then move the background like this:
background.x = (background.x - movementX + width) % width;
where width is the width of your orginal image (half the width of your current background)
and movementX is how far you want to move your background.
If you want i can explain what the thought behind this code is.
I knew people will miss understand me! I don't want it to loop forever! I just want it to loop when ever it reach the end of the screen which is the white area, so the white area will not be shown when the background loops or am I not understanding how your code work?
this is how I used the code !
var bgWidth:Number= 1588.15;
var movementX:Number = 0;
this.addEventListener(Event.ENTER_FRAME,moveLeft);
stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed);
function KeyPressed(e:KeyboardEvent):void
{
if(e.keyCode == 68){
movementX+=1;
}
}
function moveLeft(e:Event):void
{
mc_bgMid.x= (mc_bgMid.x - movementX + bgWidth) % bgWidth;
}