if(GetCommonData("BackgroundStop")==0){

let i=0; let a=0; let distance=80;
	while(i<length(tree)){ tree[i]=a+treescroll[i]; a+=distance;
		if(tree[i]>400){
		treescroll[i]=treescroll[i]-(length(tree)*distance);
		treerandomangle[i]=rand_int(0,360);
		treerandomx[i]=rand_int(0,100);
		}
	treescroll[i]=treescroll[i]+scrollspeed; i++; }
	
} //BackgroundStop = 0

if(GetCommonData("BackgroundStop")!=1){

if(bgphase==2){
if(time%120==0 && time>=1){
let xsize=30;
let ysize=150;
	EFlightray=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFlightray,cx,cy);
	ObjEffect_SetScale(EFlightray,rand(2,4),5); ObjEffect_SetAngle(EFlightray,0,0,rand(-10,10));
	ObjEffect_SetLayer(EFlightray,1); ObjEffect_SetTexture(EFlightray,BGlightray); ObjEffect_SetRenderState(EFlightray,ADD);
	ObjEffect_SetPrimitiveType(EFlightray,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFlightray,4);
	ObjEffect_SetVertexXY(EFlightray,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFlightray,0,0,0);
	ObjEffect_SetVertexXY(EFlightray,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(EFlightray,1,xsize,0);
	ObjEffect_SetVertexXY(EFlightray,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFlightray,2,0,ysize);
	ObjEffect_SetVertexXY(EFlightray,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(EFlightray,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFlightray,0,0,255,255,255); ObjEffect_SetVertexColor(EFlightray,1,0,255,255,255);
	ObjEffect_SetVertexColor(EFlightray,2,0,255,255,255); ObjEffect_SetVertexColor(EFlightray,3,0,255,255,255);
	lightray=lightray~[EFlightray];
	lightraytimer=lightraytimer~[EFlightray]; lightraytimer[length(lightray)-1]=0;
	lightrayfade=lightrayfade~[EFlightray]; lightrayfade[length(lightray)-1]=0;
	lightrayscroll=lightrayscroll~[EFlightray];
	let random=0; if(sin(time/2)>=0){ random=1; } if(sin(time/2)<0){ random=2; }
	if(random==1){ lightrayscroll[length(lightray)-1]=0.75; } if(random==2){ lightrayscroll[length(lightray)-1]=-0.75; }
}

let i=0;
while(i<length(lightray)){
	if(Obj_BeDeleted(lightray[i])){
	lightray=erase(lightray,i); lightraytimer=erase(lightraytimer,i); lightrayfade=erase(lightrayfade,i); lightrayscroll=erase(lightrayscroll,i);
	i--;
	}
	else{
	Obj_SetX(lightray[i],Obj_GetX(lightray[i])+lightrayscroll[i]);
	ObjEffect_SetVertexColor(lightray[i],0,lightrayfade[i],255,255,255); ObjEffect_SetVertexColor(lightray[i],1,lightrayfade[i],255,255,255);
	ObjEffect_SetVertexColor(lightray[i],2,lightrayfade[i],255,255,255); ObjEffect_SetVertexColor(lightray[i],3,lightrayfade[i],255,255,255);
	if(lightrayfade[i]<100){ lightrayfade[i]=lightrayfade[i]+1; }
	if(Obj_GetX(lightray[i])<minx-100 || Obj_GetX(lightray[i])>maxx+100){ Obj_Delete(lightray[i]); }
	ObjEffect_SetAngle(lightray[i],0,0,-lightrayscroll[i]*lightraytimer[i]/20);
	lightraytimer[i]=lightraytimer[i]+1;
	}
i++;
}
} //bgphase 2

} //BackgroundStop != 1


if(GetCommonData("BackgroundStop")==0){
	hscroll-=scrollspeed; vscroll-=scrollspeed;
	scroll+=scrollspeed; if(scroll>=600){ scroll-=600; }
} //BackgroundStop = 0