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

if(bgphase==1){
	scrollspeed=scrollspeed+0.005;
}
if(bgphasetime==4000 && bgphase==1){ bgphase=2; bgphasetime=0; }

if(bgphase==2){
	scrollspeed=scrollspeed+0.005;
	if(bg1fade>0){ bg1fade-=0.5; }
	if(bg1distance<500){ bg1distance+=1; }
	if(bg2distance>0 && bgphasetime>=200){ bg2distance-=2; }
	if(bg2spin<540 && bgphasetime>=200){ bg2spin+=1; }
	if(bg2spin>=540 && bgphasetime>=200 && bgphasetime<2080){ bg2vscroll+=1; }
	if(bg2spin>=540 && bgphasetime>=2080 && bgphasetime<3610){ bg2rotate+=1; }
	if(bg2spin>=540 && bgphasetime>=3610 && bgphasetime<5760){ bg2vscroll-=1; }
	if(bg2spin>=540 && bgphasetime>=5760 && bgphasetime<5900){ bg2height+=1; bg2distance-=2; bg2spin+=1; }
}
if(bgphasetime==5900 && bgphase==2){ bgphase=3; bgphasetime=0; }

if(bgphase==3){
	scrollspeed=5;
	if(bg3distance>20){ bg3viewspin+=1; }
	if(bg3distance<=20){ bg3viewspin+=1*cos(90+bgphasetime/3); }
	if(bg3distance>20){ bg3distance-=0.20; }
	if(bg3fade<255){ bg3fade+=0.5; }
}

bgphasetime++;

if(time%60==0){
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,GRlightray); 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=rand_int(1,2);
	if(random==1){ lightrayscroll[length(lightray)-1]=1.5; } if(random==2){ lightrayscroll[length(lightray)-1]=-1.5; }
}

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++;
}


hscroll-=scrollspeed; vscroll-=scrollspeed;

} //BackgroundStop