
let path_dummy		= GetCurrentScriptDirectory() ~ "img/Effect_White.png";
let path_switch		= GetCurrentScriptDirectory() ~ "img/eff_switch.png";

task CallSwitch(wait,rgb_h,lay){
	let bg		= ObjPrim_Create(OBJ_SPRITE_2D);
	let ID		= [ObjPrim_Create(OBJ_SPRITE_2D),
					ObjPrim_Create(OBJ_SPRITE_2D),
					ObjPrim_Create(OBJ_SPRITE_2D),
					ObjPrim_Create(OBJ_SPRITE_2D),
					];
	let sca		= 8;
	let sca1	= 0;
	let scaA	= 0;
	let sca2	= 0;
	let scaB	= 0;
	let i		= 0;
	
	ObjRender_SetPosition(bg, 320, 240, 0 );
	ObjPrim_SetTexture(bg, path_dummy );
	Obj_SetRenderPriorityI(bg, lay + 1 );
	ObjRender_SetBlendType(bg, BLEND_ALPHA );
	ObjRender_SetScaleXYZ(bg, 1, 1, 0 );
	ObjRender_SetColor(bg, rgb_h[0], rgb_h[1], rgb_h[2] );
	ObjSprite2D_SetSourceRect(bg, 0, 0, 640, 480 );
	ObjSprite2D_SetDestCenter(bg);
	
	loop( length(ID) ){
		ObjPrim_SetTexture(ID[i], path_switch );
		Obj_SetRenderPriorityI(ID[i], lay );
		ObjRender_SetBlendType(ID[i], BLEND_ALPHA );
		ObjRender_SetScaleXYZ(ID[i], sca/2, sca1*sca, 0 );
		ObjRender_SetColor(ID[i], rgb_h[0], rgb_h[1], rgb_h[2] );
		ObjSprite2D_SetSourceRect(ID[i], 0, 2, 256, 128 );
		ObjSprite2D_SetDestRect(ID[i], -64, -120, 64, 8 );
		i++;
	}
	i = 0;
	
	while( sca2 < 1 ){
		ObjRender_SetAlpha(bg, sca2*255 );
		
		ObjRender_SetPosition(ID[0], 0 - 128+sca1*128, 240, 0 );
		ObjRender_SetPosition(ID[1], 640 + 128-sca1*128, 240, 0 );
		ObjRender_SetPosition(ID[2], 0 - 128+sca1*128, 480, 0 );
		ObjRender_SetPosition(ID[3], 640 + 128-sca1*128, 480, 0 );
		ObjRender_SetAngleXYZ(ID[0], 0, 0, 64+8 );
		ObjRender_SetAngleXYZ(ID[1], 0, 0, -64-8 );
		ObjRender_SetAngleXYZ(ID[2], 0, 0, 64+8 );
		ObjRender_SetAngleXYZ(ID[3], 0, 0, -64-8 );
		
		loop( length(ID)/2 ){
			ObjRender_SetScaleXYZ(ID[i], sca/2, sca2*sca, 0 );
			ObjRender_SetScaleXYZ(ID[2+i], sca/2, sca1*sca, 0 );
			i++;
		}
		i = 0;
		
		if( sca1 < 1 ){ scaA += 3; }
		sca1 = 1 * sin( scaA );
		if( sca1 >= 0.8 ){ scaB += 3; }
		sca2 = 1 * sin( scaB );
		
		yield;
	}
	loop( wait ){ yield; }
	while( sca1 > 0 ){
		ObjRender_SetAlpha(bg, sca2*255 );
		
		ObjRender_SetPosition(ID[0], 0 - 128-sca1*128, 80, 0 );
		ObjRender_SetPosition(ID[1], 640 + 128+sca1*128, 80, 0 );
		ObjRender_SetPosition(ID[2], 0 - 128-sca1*128, 480, 0 );
		ObjRender_SetPosition(ID[3], 640 + 128+sca1*128, 480, 0 );
		ObjRender_SetAngleXYZ(ID[0], 180, 0, 64+8 );
		ObjRender_SetAngleXYZ(ID[1], 180, 0, -64-8 );
		ObjRender_SetAngleXYZ(ID[2], 180, 0, 64+8 );
		ObjRender_SetAngleXYZ(ID[3], 180, 0, -64-8 );
		
		loop( length(ID)/2 ){
			ObjRender_SetScaleXYZ(ID[i], sca/2, sca2*sca, 0 );
			ObjRender_SetScaleXYZ(ID[2+i], sca/2, sca1*sca, 0 );
			i++;
		}
		i = 0;
		
		if( sca2 <= 0.98 ){ scaA += 3; }
		sca1 = 1 * sin( scaA );
		if( sca2 > 0 ){ scaB += 3; }
		sca2 = 1 * sin( scaB );
		
		yield;
	}
	Obj_Delete(bg);
	loop( length(ID) ){
		Obj_Delete(ID[i]);
		i++;
	}
	i = 0;
}

task CallSwitch_OnGame(wait,rgb_h){
	let bg		= ObjPrim_Create(OBJ_SPRITE_2D);
	let ID		= [ObjPrim_Create(OBJ_SPRITE_2D),
					ObjPrim_Create(OBJ_SPRITE_2D),
					ObjPrim_Create(OBJ_SPRITE_2D),
					ObjPrim_Create(OBJ_SPRITE_2D),
					];
	let sca		= 8;
	let sca1	= 0;
	let scaA	= 0;
	let sca2	= 0;
	let scaB	= 0;
	let lay		= 21;
	let i		= 0;
	
	ObjRender_SetPosition(bg, GetStgFrameWidth()/2, GetStgFrameHeight()/2, 0 );
	ObjPrim_SetTexture(bg, path_dummy );
	Obj_SetRenderPriorityI(bg, lay + 1 );
	ObjRender_SetBlendType(bg, BLEND_ALPHA );
	ObjRender_SetScaleXYZ(bg, 1, 1, 0 );
	ObjRender_SetColor(bg, rgb_h[0], rgb_h[1], rgb_h[2] );
	ObjSprite2D_SetSourceRect(bg, 0, 0, 384, 448 );
	ObjSprite2D_SetDestCenter(bg);
	
	loop( length(ID) ){
		ObjPrim_SetTexture(ID[i], path_switch );
		Obj_SetRenderPriorityI(ID[i], lay );
		ObjRender_SetBlendType(ID[i], BLEND_ALPHA );
		ObjRender_SetScaleXYZ(ID[i], sca/2, sca1*sca, 0 );
		ObjRender_SetColor(ID[i], rgb_h[0], rgb_h[1], rgb_h[2] );
		ObjSprite2D_SetSourceRect(ID[i], 0, 2, 256, 128 );
		ObjSprite2D_SetDestRect(ID[i], -64, -120, 64, 8 );
		i++;
	}
	i = 0;
	
	while( sca2 < 1 ){
		ObjRender_SetAlpha(bg, sca2*255 );
		
		ObjRender_SetPosition(ID[0], 0 - 128+sca1*128, 240, 0 );
		ObjRender_SetPosition(ID[1], 384 + 128-sca1*128, 240, 0 );
		ObjRender_SetPosition(ID[2], 0 - 128+sca1*128, 480, 0 );
		ObjRender_SetPosition(ID[3], 384 + 128-sca1*128, 480, 0 );
		ObjRender_SetAngleXYZ(ID[0], 0, 0, 64+8 );
		ObjRender_SetAngleXYZ(ID[1], 0, 0, -64-8 );
		ObjRender_SetAngleXYZ(ID[2], 0, 0, 64+8 );
		ObjRender_SetAngleXYZ(ID[3], 0, 0, -64-8 );
		
		loop( length(ID)/2 ){
			ObjRender_SetScaleXYZ(ID[i], sca/2, sca2*sca, 0 );
			ObjRender_SetScaleXYZ(ID[2+i], sca/2, sca1*sca, 0 );
			i++;
		}
		i = 0;
		
		if( sca1 < 1 ){ scaA += 3; }
		sca1 = 1 * sin( scaA );
		if( sca1 >= 0.8 ){ scaB += 3; }
		sca2 = 1 * sin( scaB );
		
		yield;
	}
	loop( wait ){ yield; }
	while( sca1 > 0 ){
		ObjRender_SetAlpha(bg, sca2*255 );
		
		ObjRender_SetPosition(ID[0], 0 - 128-sca1*128, 80, 0 );
		ObjRender_SetPosition(ID[1], 384 + 128+sca1*128, 80, 0 );
		ObjRender_SetPosition(ID[2], 0 - 128-sca1*128, 480, 0 );
		ObjRender_SetPosition(ID[3], 384 + 128+sca1*128, 480, 0 );
		ObjRender_SetAngleXYZ(ID[0], 180, 0, 64+8 );
		ObjRender_SetAngleXYZ(ID[1], 180, 0, -64-8 );
		ObjRender_SetAngleXYZ(ID[2], 180, 0, 64+8 );
		ObjRender_SetAngleXYZ(ID[3], 180, 0, -64-8 );
		
		loop( length(ID)/2 ){
			ObjRender_SetScaleXYZ(ID[i], sca/2, sca2*sca, 0 );
			ObjRender_SetScaleXYZ(ID[2+i], sca/2, sca1*sca, 0 );
			i++;
		}
		i = 0;
		
		if( sca2 <= 0.98 ){ scaA += 3; }
		sca1 = 1 * sin( scaA );
		if( sca2 > 0 ){ scaB += 3; }
		sca2 = 1 * sin( scaB );
		
		yield;
	}
	Obj_Delete(bg);
	loop( length(ID) ){
		Obj_Delete(ID[i]);
		i++;
	}
	i = 0;
}

task LoadingDefault2(x,y,long){
	let id		= [ObjPrim_Create(OBJ_SPRITE_2D),
					ObjPrim_Create(OBJ_SPRITE_2D)];
	let csd		= GetCurrentScriptDirectory();
	let i		= 0;
	let move1	= 0;
	let moveA	= 0;
	let alpha1	= 0;
	let alphaA	= 0;
	let cc		= 0;
	
	loop( length(id) ){
		ObjRender_SetPosition(id[i], x, y, 0 );
		ObjPrim_SetTexture(id[i], GetCurrentScriptDirectory ~ "../img/menu/load_eff.png" );
		Obj_SetRenderPriorityI(id[i], 83 );
		ObjRender_SetBlendType(id[i], BLEND_ALPHA);
		ObjRender_SetScaleXYZ(id[i], 0.8, 0.8, 0 );
		ObjRender_SetAlpha(id[i], alpha1*255 );
		ObjSprite2D_SetSourceRect(id[0], 0, 0, 200, 50 );
		ObjSprite2D_SetSourceRect(id[1], 0, 51, 200, 101 );
		ObjSprite2D_SetDestCenter(id[i]);
		i++;
	}
	i = 0;
	
	loop( long ){
		alpha1 = 1 * sin( alphaA );
		move1 = 1 * sin( moveA );
		
		if( cc%6 == 0 ){
			//@ศ๑ฉoทอRRษ
			//CreateSnowflake(id[0], [x + rand(-98,98),y - rand(16,32)], 90 + rand(-16,16), 0.8, 0, 10, [255,255,255], 255, 60 );
			//Butterfly( [x + rand(-98,114),y + rand(-32,48)], rand(0.2,0.4), rand(32,64), 225, 0, [128,192,255] );
			yield;
		}
		
		ObjRender_SetPosition(id[1], ObjRender_GetX(id[0])+100-move1*70, ObjRender_GetY(id[0])+20, 0 );
		
		ObjRender_SetColor(id[0], 200+55*sin(cc), 200+55*sin(cc), 200+55*sin(cc) );
		ObjRender_SetAlpha(id[0], alpha1*255 );
		ObjRender_SetColor(id[1], 225+30*sin(cc), 225+30*sin(cc), 225+30*sin(cc) );
		ObjRender_SetAlpha(id[1], alpha1*255 );
		
		cc += 5;
		if( alpha1 < 1 ){ alphaA += 5; }
		if( move1 < 1 ){ moveA += 5; }
		
		yield;
	}
	
	alpha1 = 0;
	alphaA = 0;
	while( alpha1 < 1 ){
		alpha1 = 1 * sin( alphaA );
		
		ObjRender_SetColor(id[0], 200+55*sin(cc), 200+55*sin(cc), 200+55*sin(cc) );
		ObjRender_SetAlpha(id[0], 255 - alpha1*255 );
		ObjRender_SetColor(id[1], 225+30*sin(cc), 225+30*sin(cc), 225+30*sin(cc) );
		ObjRender_SetAlpha(id[1], 255 - alpha1*255 );
		
		cc += 5;
		if( alpha1 < 1 ){ alphaA += 5; }
		
		yield;
	}
	Obj_Delete(id[0]);
	Obj_Delete(id[1]);
}