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

let i=0; let a=0; let distance=80;
	while(i<length(bush)){ bush[i]=a+bushscroll[i]; a+=distance;
		if(bush[i]>400){
		bushscroll[i]=bushscroll[i]-(length(bush)*distance);
		bushrandomx[i]=randombush2;
		}
	bushscroll[i]=bushscroll[i]+scrollspeed; i++; }
let i=0; let a=0; let distance=100;
	while(i<length(canopy)){ canopy[i]=a+canopyscroll[i]; a+=distance;
	if(canopy[i]>400){
		canopysprite+=rand_int(1,2); if(canopysprite>3){ canopysprite-=3; }
		canopyscroll[i]=canopyscroll[i]-(length(canopy)*distance);
		canopygraphic[i]=canopysprite;
		}
	canopyscroll[i]=canopyscroll[i]+scrollspeed; i++; }

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

if(time%10==0 && time>=1){
let fall=rand_int(1,5);
	if(fall==4){
	leaf=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(leaf,cx+rand(-200,200),miny);
	Obj_SetSpeed(leaf,rand(3,4)); ObjEffect_SetScale(leaf,rand(0.5,1.2),rand(0.5,1.2)); Obj_SetAutoDelete(leaf,true); 
	Obj_SetAngle(leaf,rand(110,70)); ObjEffect_SetAngle(leaf,rand(0,360),rand(0,360),rand(0,360));
	ObjEffect_SetLayer(leaf,1); ObjEffect_SetTexture(leaf,BGleaf); ObjEffect_SetRenderState(leaf,ALPHA);
	ObjEffect_SetPrimitiveType(leaf,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(leaf,4);
	ObjEffect_SetVertexXY(leaf,0,-25,-25); ObjEffect_SetVertexUV(leaf,0,0,0);
	ObjEffect_SetVertexXY(leaf,1,25,-25); ObjEffect_SetVertexUV(leaf,1,50,0);
	ObjEffect_SetVertexXY(leaf,2,-25,25); ObjEffect_SetVertexUV(leaf,2,0,50);
	ObjEffect_SetVertexXY(leaf,3,25,25); ObjEffect_SetVertexUV(leaf,3,50,50);
	let colorR=rand_int(50,150);
	ObjEffect_SetVertexColor(leaf,0,155,colorR,155,0); ObjEffect_SetVertexColor(leaf,1,155,colorR,155,0);
	ObjEffect_SetVertexColor(leaf,2,155,colorR,155,0); ObjEffect_SetVertexColor(leaf,3,155,colorR,155,0);
	leaves=leaves~[leaf];
	}
}

hscroll-=scrollspeed; vscroll-=scrollspeed;
scroll+=scrollspeed; if(scroll>=600){ scroll-=600; }

} //Background stop

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]<20){ lightrayfade[i]=lightrayfade[i]+0.3; }
	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++;
}

let i=0; leaftimer=leaftimer~[leaf];
while (i<length(leaves)){
	if(Obj_BeDeleted(leaves[i])){ leaves=erase(leaves,i); leaftimer=erase(leaftimer,i); i--; }
	else{
	leaftimer[i]=leaftimer[i]+rand(1,2);
	ObjEffect_SetAngle(leaves[i],leaftimer[i]*1.1,leaftimer[i]*1.23,-leaftimer[i]*0.61);
	if(Obj_GetY(leaves[i])>500){ Obj_Delete(leaves[i]); }
	}
i++;
}