--// Local auxiliary functions - - - - - - - - - - - - - - - - - - - - - - - -

--// 1.	rename:					" -> '
--// 2. comment root composition routines:
--//	"createCompositionBg01 = function()",
--//	"createCompositionBg01 = function()"
--// 5. add auxiliaru routines for managing animations: 
--		auxPlayShamansHutAnimation(), 
--		auxGetShamansHutAnimation(), 
--		auxCreateShamansHutAnimations()

------------------------------------------------------------------------------
--
function auxPlayShamansHutAnimation(compositionName)
    local composition = auxGetShamansHutAnimation(compositionName);
    composition:SetVisible(true);
    composition:Play();
end

------------------------------------------------------------------------------
--
function auxHideShamansHutAnimation(compositionName)
    local composition = auxGetShamansHutAnimation(compositionName);
    composition:Stop();
    composition:SetVisible(false);
end

------------------------------------------------------------------------------
--
function auxGetShamansHutAnimation(compositionName)
    assert(shamansHutCompositions ~= nil and compositionName ~= nil);
	assert(shamansHutCompositions[compositionName] ~= nil and 'Composition with specified name not exists !');

    return shamansHutCompositions[compositionName];
end

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
--

function CreateComposition(parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic)
    assert(parent ~= nil and compositionRoutine ~= nil and name ~= nil and z ~= nil and duration ~= nil);

    local element = compositionRoutine();
    element:SetName(name);
    element:SetHotSpot(hotSpotX,hotSpotY);
    element:SetXY(x, y);
    assert(z - parent:GetZ());
    element:SetZ(z - parent:GetZ());
    element:AttachTo(parent);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    if (isCyclic == true) then
        element:SetDuration(duration);
        element:SetCyclic(true);
	else
		element:SetDestroysOnEnd(false);
    end
	element:Stop();
    element:SetVisible(false);
    element:AssignClippingRect(parent);
	element:SetConsiderParentOpacity(true);

	return element;
end

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function auxCreateCompositionElement(resourceName)
	local element = CreateCompositionElement(resourceName);
    local texName = string.sub(resourceName, string.len('data/Texture/Scenes/12_ShamansHut/Animations/') + 1);

	--// set up flies animation
	if (texName == 'Env/Bug_fly[01-02].png') then
		local anim = element:GetTexture();
		anim:Stop();
		anim:SetTextureRect(0,0, 19,18);
		anim:SetFrames(2);
		anim:SetFrame(0);
		anim:SetSpeed(30.0);
		anim:SetMode(HGEANIM_FWD + HGEANIM_LOOP);
		anim:Play();
    end
	--// set up spider animation
	if (texName == 'Env/[01-10].png') then
		local anim = element:GetTexture();
		anim:Stop();
		anim:SetTextureRect(0,0, 89,123);
		anim:SetFrames(10);
		anim:SetFrame(0);
		anim:SetSpeed(30.0);
		anim:SetMode(HGEANIM_FWD + HGEANIM_LOOP);
		anim:Play();
    end

    --// set additive alpha blending mode for light & flare objects without alpha chanel (*.jpg)
    if (texName == 'Env/entranceLight_02.jpg') then

        element:GetTexture():SetBlendMode(0);
    end
	return element;
end

------------------------------------------------------------------------------
--
function auxCreateShamansHutAnimations(parent)
    assert(parent ~= nil);
    shamansHutCompositions = {};
    local CreateAndRegisterComposition = function (parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic)
        local element = CreateComposition(parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic);
        shamansHutCompositions[element:GetName()] = element;
    end
    
    CreateAndRegisterComposition(parent, createCompositionSleep,	'GuardianSleep', 0,0,99.0, 532,414, 4, false);
    CreateAndRegisterComposition(parent, createCompositionIdle01,	'GuardianIdle',  0,0,99.0, 512,390, 4, true);
	-- Env
    CreateAndRegisterComposition(parent, createCompositionEnvTop,	'EnvTop',	0,0,99.0, 512,390, 10, true);
    CreateAndRegisterComposition(parent, createCompositionFly1, 	'Fly1',  	0,0,99.0, 512,390, 10, false);
    CreateAndRegisterComposition(parent, createCompositionFly2, 	'Fly2',  	0,0,99.0, 512,390, 10, false);
    CreateAndRegisterComposition(parent, createCompositionSpider2,	'Spider2',  0,0,99.0, 512,390, 10, false);
end

------------------------------------------------------------------------------
--
--createCompositionBg01 = function()
--    local compositionBg01 = CreateCompositionSequence();
--    local compositionDuration = 4;
--    compositionBg01:SetDuration(compositionDuration);
--
--
--    -- Layer Layer_1
--    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/L_aborigen.png');
--    element:SetName('Layer_1');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(142.5, 249.5);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(881.5, 340.5);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 4);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_2
--    local element = createCompositionSleep();
--    element:SetName('Layer_2');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 4);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_3
--    local element = createCompositionIdle01();
--    element:SetName('Layer_3');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 4);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_4
--    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/Bg01.jpg');
--    element:SetName('Layer_4');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 4);
--
--
--    effector:Play();
--
--    compositionBg01:Play();
--
--    return compositionBg01;
--end

createCompositionIdle01 = function()

    local compositionIdle01 = CreateCompositionSequence();
    local compositionDuration = 4;
    compositionIdle01:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/golova.png');
    element:SetName('Layer_1');
    compositionIdle01:AddElement(element);
    element:SetHotSpot(24, 59.5);
    compositionIdle01:RegisterParentInfo('Layer_1', 'Layer_2');
    element:SetXY(54, 56.5);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_A, 0, -0.06597900011258);
    effector:SetKey(_TRACK_A, 0.96, -0.0209508087037);
    effector:SetKey(_TRACK_A, 2.16, 0.02541135168515);
    effector:SetKey(_TRACK_A, 3.96, -0.06597900011258);

    effector:Play();


    -- Layer Layer_2
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/tylyb.png');
    element:SetName('Layer_2');
    compositionIdle01:AddElement(element);
    element:SetHotSpot(53.5, 150);
    element:SetParentElement(compositionIdle01);
    element:SetXY(890.5, 403);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_A, 0, 0.0521498968645);
    effector:SetKey(_TRACK_A, 1.24, 0.0721219700512);
    effector:SetKey(_TRACK_A, 2.88, 0.04006298693635);
    effector:SetKey(_TRACK_A, 3.96, 0.0521498968645);

    effector:Play();


    -- Layer Layer_3
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/pleche.png');
    element:SetName('Layer_3');
    compositionIdle01:AddElement(element);
    element:SetHotSpot(30, 13.5);
    compositionIdle01:RegisterParentInfo('Layer_3', 'Layer_2');
    element:SetXY(31.5, 71.5);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_A, 0, -0.10669429381815);
    effector:SetKey(_TRACK_A, 0.88, -0.18360758317521);
    effector:SetKey(_TRACK_A, 3.96, -0.10669429381815);

    effector:Play();


    -- Layer Layer_4
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/ryka.png');
    element:SetName('Layer_4');
    compositionIdle01:AddElement(element);
    element:SetHotSpot(21, 52.5);
    compositionIdle01:RegisterParentInfo('Layer_4', 'Layer_3');
    element:SetXY(9.84858929416816, 60.54434765798);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_A, 0, 0.11399948383698);
    effector:SetKey(_TRACK_A, 1.48, 0.11349384417372);
    effector:SetKey(_TRACK_A, 2.76, 0.1244731672267);
    effector:SetKey(_TRACK_A, 3.96, 0.11399948383698);

    effector:Play();


    -- Layer Layer_5
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/kopie.png');
    element:SetName('Layer_5');
    compositionIdle01:AddElement(element);
    element:SetHotSpot(19.5, 98);
    compositionIdle01:RegisterParentInfo('Layer_5', 'Layer_4');
    element:SetXY(12.1954636567908, 7.68299959357095);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(-0.02729782664621);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);


    effector:Play();

    compositionIdle01:Play();

    return compositionIdle01;
end

createCompositionSleep = function()

    local compositionSleep = CreateCompositionSequence();
    local compositionDuration = 4;
    compositionSleep:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/dust_fall01.png');
    element:SetName('Layer_1');
    compositionSleep:AddElement(element);
    element:SetHotSpot(32, 32);
    element:SetParentElement(compositionSleep);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_X, 1.84, 898);
    effector:SetKey(_TRACK_Y, 1.84, 428);
    effector:SetKey(_TRACK_X, 2.4580078125, 887);
    effector:SetKey(_TRACK_Y, 2.4580078125, 355);
    effector:SetKey(_TRACK_X, 3, 879);
    effector:SetKey(_TRACK_Y, 3, 314);
    effector:SetKey(_TRACK_SX, 1.84, 1.43750000000001);
    effector:SetKey(_TRACK_SY, 1.84, 1.28125000000001);
    effector:SetKey(_TRACK_SX, 2.4580078125, 3.43750000000001);
    effector:SetKey(_TRACK_SY, 2.4580078125, 2.68750000000001);
    effector:SetKey(_TRACK_SX, 3, 3.75000000000001);
    effector:SetKey(_TRACK_SY, 3, 3.06250000000001);
    effector:SetKey(_TRACK_A, 1.84, 0.25176645769327);
    effector:SetKey(_TRACK_A, 3, -0.35264119604645);
    effector:SetKey(_TRACK_O, 1.84, 1);
    effector:SetKey(_TRACK_O, 2.44, 0.8);
    effector:SetKey(_TRACK_O, 3, 0.01);

    effector:Play();


    -- Layer Layer_2
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/golova.png');
    element:SetName('Layer_2');
    compositionSleep:AddElement(element);
    element:SetHotSpot(24, 59.5);
    compositionSleep:RegisterParentInfo('Layer_2', 'Layer_3');
    element:SetXY(54, 56.5);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_A, 0, -0.06597900011258);
    effector:SetKey(_TRACK_A, 0.5726171875, 0.29830804924525);
    effector:SetKey(_TRACK_A, 0.930546875, 0.07480836086443);
    effector:SetKey(_TRACK_A, 1.216875, -0.35524649181254);
    effector:SetKey(_TRACK_A, 1.86109375, -0.61544980542089);

    effector:Play();


    -- Layer Layer_3
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/tylyb.png');
    element:SetName('Layer_3');
    compositionSleep:AddElement(element);
    element:SetHotSpot(53.5, 150);
    element:SetParentElement(compositionSleep);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_X, 1.56046875, 913);
    effector:SetKey(_TRACK_Y, 1.56046875, 429.5);
    effector:SetKey(_TRACK_X, 1.764140625, 924.5);
    effector:SetKey(_TRACK_Y, 1.764140625, 461.5);
    effector:SetKey(_TRACK_A, 0, 0.0521498968645);
    effector:SetKey(_TRACK_A, 1.09875, -0.06329998483904);
    effector:SetKey(_TRACK_A, 1.56046875, 0.23397596138739);
    effector:SetKey(_TRACK_A, 1.764140625, 0.71910913493388);

    effector:Play();


    -- Layer Layer_4
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/pleche.png');
    element:SetName('Layer_4');
    compositionSleep:AddElement(element);
    element:SetHotSpot(30, 13.5);
    compositionSleep:RegisterParentInfo('Layer_4', 'Layer_3');
    element:SetXY(31.5, 71.5);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_A, 0, -0.10669429381815);
    effector:SetKey(_TRACK_A, 0.79546875, 0.05253025412621);
    effector:SetKey(_TRACK_A, 1.034140625, -0.16468759730837);
    effector:SetKey(_TRACK_A, 1.431875, 0.62243821532708);
    effector:SetKey(_TRACK_A, 1.909140625, -0.33694342830937);

    effector:Play();


    -- Layer Layer_5
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/ryka.png');
    element:SetName('Layer_5');
    compositionSleep:AddElement(element);
    element:SetHotSpot(21, 52.5);
    compositionSleep:RegisterParentInfo('Layer_5', 'Layer_4');
    element:SetXY(9.84858929416816, 60.54434765798);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_A, 0, 0.11399948383698);
    effector:SetKey(_TRACK_A, 0.3094140625, -0.00080495436247);
    effector:SetKey(_TRACK_A, 0.6187890625, -0.28780145488769);
    effector:SetKey(_TRACK_A, 1.005546875, -0.11864136461028);
    effector:SetKey(_TRACK_A, 1.54703125, -0.72849620406389);
    effector:SetKey(_TRACK_A, 1.85640625, -1.51534556803858);

    effector:Play();


    -- Layer Layer_6
    local element = CreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Guardian/kopie.png');
    element:SetName('Layer_6');
    compositionSleep:AddElement(element);
    element:SetHotSpot(19.5, 98);
    compositionSleep:RegisterParentInfo('Layer_6', 'Layer_5');
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 4);

    effector:SetKey(_TRACK_X, 1.84, 12.1954636567908);
    effector:SetKey(_TRACK_Y, 1.84, 7.68299959357095);
    effector:SetKey(_TRACK_X, 2.04, 58.3148679688285);
    effector:SetKey(_TRACK_Y, 2.04, -28.2474964495271);
    effector:SetKey(_TRACK_X, 2.24, 8.57240631993142);
    effector:SetKey(_TRACK_Y, 2.24, 9.37812658993128);
    effector:SetKey(_TRACK_A, 0, -0.02729782664621);
    effector:SetKey(_TRACK_A, 1.84, -0.02729782664621);
    effector:SetKey(_TRACK_A, 2.24, -5.99500432430756);

    effector:Play();

    compositionSleep:Play();

    return compositionSleep;
end

------------------------------------------------------------------------------
-- Env
--createCompositionBg01 = function()
--
--    local compositionBg01 = CreateCompositionSequence();
--    local compositionDuration = 10;
--    compositionBg01:SetDuration(compositionDuration);
--
--
--    -- Layer Layer_1
--    local element = createCompositionEnvTop();
--    element:SetName('Layer_1');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_2
--    local element = createCompositionFly1();
--    element:SetName('Layer_2');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_3
--    local element = createCompositionFly2();
--    element:SetName('Layer_3');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_5
--    local element = createCompositionSpider2();
--    element:SetName('Layer_5');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_6
--    local element = auxCreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Env/Bg01.jpg');
--    element:SetName('Layer_6');
--    compositionBg01:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionBg01);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();
--
--    compositionBg01:Play();
--
--    return compositionBg01;
--end

createCompositionEnvTop = function()

    local compositionEnvTop = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionEnvTop:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Env/entranceLight_02.jpg');
    element:SetName('Layer_1');
    compositionEnvTop:AddElement(element);
    element:SetHotSpot(50, 57.5);
    element:SetParentElement(compositionEnvTop);
    element:SetXY(512, 460.540542602539);

    element:SetScaleX(4.8918918918919);
    element:SetScaleY(4.02326674500588);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 0, 0.2);
    effector:SetKey(_TRACK_O, 1.4, 0.6);
    effector:SetKey(_TRACK_O, 2.76, 0.2);
    effector:SetKey(_TRACK_O, 4.24, 0.6);
    effector:SetKey(_TRACK_O, 5.56, 0.6);
    effector:SetKey(_TRACK_O, 6.68, 0.1);
    effector:SetKey(_TRACK_O, 7.64, 0.6);
    effector:SetKey(_TRACK_O, 8.52, 0.2);
    effector:SetKey(_TRACK_O, 9.16, 0.4);
    effector:SetKey(_TRACK_O, 10, 0.2);

    effector:Play();

    compositionEnvTop:Play();

    return compositionEnvTop;
end

createCompositionFly1 = function()

    local compositionFly1 = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionFly1:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Env/Bug_fly[01-02].png');
    element:SetName('Layer_1');
    compositionFly1:AddElement(element);
    element:SetHotSpot(9.5, 9);
    element:SetParentElement(compositionFly1);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_X, 0, 722.824325561523);
    effector:SetKey(_TRACK_Y, 0, 809.918914794922);
    effector:SetKey(_TRACK_X, 0.08, 709.824325561523);
    effector:SetKey(_TRACK_Y, 0.08, 778.918914794922);
    effector:SetKey(_TRACK_X, 0.28, 670.324325561523);
    effector:SetKey(_TRACK_Y, 0.28, 741.418914794922);
    effector:SetKey(_TRACK_X, 0.56, 593.324325561523);
    effector:SetKey(_TRACK_Y, 0.56, 707.418914794922);
    effector:SetKey(_TRACK_X, 0.84, 502.324325561523);
    effector:SetKey(_TRACK_Y, 0.84, 685.918914794922);
    effector:SetKey(_TRACK_X, 1.08, 434.824325561523);
    effector:SetKey(_TRACK_Y, 1.08, 646.418914794922);
    effector:SetKey(_TRACK_X, 1.32, 405.324325561523);
    effector:SetKey(_TRACK_Y, 1.32, 596.418914794922);
    effector:SetKey(_TRACK_X, 1.6, 369.824325561523);
    effector:SetKey(_TRACK_Y, 1.6, 569.418914794922);
    effector:SetKey(_TRACK_X, 1.8, 365.824325561523);
    effector:SetKey(_TRACK_Y, 1.8, 569.918914794922);
    effector:SetKey(_TRACK_X, 2.16, 371.824325561523);
    effector:SetKey(_TRACK_Y, 2.16, 569.918914794922);
    effector:SetKey(_TRACK_X, 2.4, 358.824325561523);
    effector:SetKey(_TRACK_Y, 2.4, 591.418914794922);
    effector:SetKey(_TRACK_X, 2.92, 363.324325561523);
    effector:SetKey(_TRACK_Y, 2.92, 549.918914794922);
    effector:SetKey(_TRACK_X, 3.08, 347.324325561523);
    effector:SetKey(_TRACK_Y, 3.08, 529.918914794922);
    effector:SetKey(_TRACK_X, 3.28, 318.324325561523);
    effector:SetKey(_TRACK_Y, 3.28, 535.418914794922);
    effector:SetKey(_TRACK_X, 3.44, 291.324325561523);
    effector:SetKey(_TRACK_Y, 3.44, 556.418914794922);
    effector:SetKey(_TRACK_X, 3.56, 274.824325561523);
    effector:SetKey(_TRACK_Y, 3.56, 587.418914794922);
    effector:SetKey(_TRACK_X, 3.72, 283.824325561523);
    effector:SetKey(_TRACK_Y, 3.72, 620.918914794922);
    effector:SetKey(_TRACK_X, 3.84, 320.824325561523);
    effector:SetKey(_TRACK_Y, 3.84, 645.418914794922);
    effector:SetKey(_TRACK_X, 3.96, 366.324325561523);
    effector:SetKey(_TRACK_Y, 3.96, 653.418914794922);
    effector:SetKey(_TRACK_X, 4.12, 421.324325561523);
    effector:SetKey(_TRACK_Y, 4.12, 644.918914794922);
    effector:SetKey(_TRACK_X, 4.32, 441.824325561523);
    effector:SetKey(_TRACK_Y, 4.32, 627.918914794922);
    effector:SetKey(_TRACK_X, 4.4, 426.324325561523);
    effector:SetKey(_TRACK_Y, 4.4, 618.918914794922);
    effector:SetKey(_TRACK_X, 4.48, 402.824325561523);
    effector:SetKey(_TRACK_Y, 4.48, 610.418914794922);
    effector:SetKey(_TRACK_X, 4.6, 377.824325561523);
    effector:SetKey(_TRACK_Y, 4.6, 606.418914794922);
    effector:SetKey(_TRACK_X, 4.88, 314.324325561523);
    effector:SetKey(_TRACK_Y, 4.88, 607.418914794922);
    effector:SetKey(_TRACK_X, 4.96, 290.824325561523);
    effector:SetKey(_TRACK_Y, 4.96, 610.418914794922);
    effector:SetKey(_TRACK_X, 5.04, 268.824325561523);
    effector:SetKey(_TRACK_Y, 5.04, 620.418914794922);
    effector:SetKey(_TRACK_X, 5.16, 248.324325561523);
    effector:SetKey(_TRACK_Y, 5.16, 635.418914794922);
    effector:SetKey(_TRACK_X, 5.36, 280.324325561523);
    effector:SetKey(_TRACK_Y, 5.36, 658.418914794922);
    effector:SetKey(_TRACK_X, 5.52, 329.575114575646);
    effector:SetKey(_TRACK_Y, 5.52, 657.918767097697);
    effector:SetKey(_TRACK_X, 5.68, 381.824325561523);
    effector:SetKey(_TRACK_Y, 5.68, 639.418914794922);
    effector:SetKey(_TRACK_X, 5.88, 424.324325561523);
    effector:SetKey(_TRACK_Y, 5.88, 606.418914794922);
    effector:SetKey(_TRACK_X, 6.12, 456.824325561523);
    effector:SetKey(_TRACK_Y, 6.12, 557.918914794922);
    effector:SetKey(_TRACK_X, 6.48, 469.324325561523);
    effector:SetKey(_TRACK_Y, 6.48, 550.418914794922);
    effector:SetKey(_TRACK_X, 6.8, 455.324325561523);
    effector:SetKey(_TRACK_Y, 6.8, 550.918914794922);
    effector:SetKey(_TRACK_X, 7.08, 492.324325561523);
    effector:SetKey(_TRACK_Y, 7.08, 571.918914794922);
    effector:SetKey(_TRACK_X, 7.36, 546.824325561523);
    effector:SetKey(_TRACK_Y, 7.36, 585.918914794922);
    effector:SetKey(_TRACK_X, 7.64, 627.324325561523);
    effector:SetKey(_TRACK_Y, 7.64, 568.918914794922);
    effector:SetKey(_TRACK_X, 7.92, 698.824325561523);
    effector:SetKey(_TRACK_Y, 7.92, 530.918914794922);
    effector:SetKey(_TRACK_X, 8.2, 749.324325561523);
    effector:SetKey(_TRACK_Y, 8.2, 467.918914794922);
    effector:SetKey(_TRACK_X, 8.44, 799.824325561523);
    effector:SetKey(_TRACK_Y, 8.44, 382.918914794922);
    effector:SetKey(_TRACK_X, 8.72, 819.324325561523);
    effector:SetKey(_TRACK_Y, 8.72, 295.918914794922);
    effector:SetKey(_TRACK_X, 8.96, 804.324325561523);
    effector:SetKey(_TRACK_Y, 8.96, 255.418914794922);
    effector:SetKey(_TRACK_X, 9.44, 804.324325561523);
    effector:SetKey(_TRACK_Y, 9.44, 255.418914794922);
    effector:SetKey(_TRACK_X, 9.6, 822.324325561523);
    effector:SetKey(_TRACK_Y, 9.6, 278.418914794922);
    effector:SetKey(_TRACK_X, 9.76, 863.824325561523);
    effector:SetKey(_TRACK_Y, 9.76, 316.918914794922);
    effector:SetKey(_TRACK_X, 9.96, 933.324325561523);
    effector:SetKey(_TRACK_Y, 9.96, 346.418914794922);
    effector:SetKey(_TRACK_SX, 0, 1.4);
    effector:SetKey(_TRACK_SY, 0, 1.4);
    effector:SetKey(_TRACK_SX, 1.6, 1);
    effector:SetKey(_TRACK_SY, 1.6, 1);
    effector:SetKey(_TRACK_SX, 2.6, 1);
    effector:SetKey(_TRACK_SY, 2.6, 1);
    effector:SetKey(_TRACK_SX, 3.56, 1.2);
    effector:SetKey(_TRACK_SY, 3.56, 1.2);
    effector:SetKey(_TRACK_SX, 4.76, 0.8);
    effector:SetKey(_TRACK_SY, 4.76, 0.8);
    effector:SetKey(_TRACK_SX, 5.52, 1.2);
    effector:SetKey(_TRACK_SY, 5.52, 1.2);
    effector:SetKey(_TRACK_SX, 6.72, 0.8);
    effector:SetKey(_TRACK_SY, 6.72, 0.8);
    effector:SetKey(_TRACK_SX, 8.96, 0.6);
    effector:SetKey(_TRACK_SY, 8.96, 0.6);
    effector:SetKey(_TRACK_SX, 9.96, 0.4);
    effector:SetKey(_TRACK_SY, 9.96, 0.4);
    effector:SetKey(_TRACK_O, 0, 1);
    effector:SetKey(_TRACK_O, 4.4, 1);
    effector:SetKey(_TRACK_O, 4.44, 0);
    effector:SetKey(_TRACK_O, 4.48, 1);
    effector:SetKey(_TRACK_O, 4.56, 0);
    effector:SetKey(_TRACK_O, 4.88, 0);
    effector:SetKey(_TRACK_O, 4.92, 1);
    effector:SetKey(_TRACK_O, 4.96, 0);
    effector:SetKey(_TRACK_O, 5, 1);
    effector:SetKey(_TRACK_O, 9.92, 1);
    effector:SetKey(_TRACK_O, 9.96, 0);

    effector:Play();

    compositionFly1:Play();

    return compositionFly1;
end

createCompositionFly2 = function()

    local compositionFly2 = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionFly2:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Env/Bug_fly[01-02].png');
    element:SetName('Layer_1');
    compositionFly2:AddElement(element);
    element:SetHotSpot(9.5, 9);
    element:SetParentElement(compositionFly2);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_X, 0, 530.081085205078);
    effector:SetKey(_TRACK_Y, 0, 287.864868164063);
    effector:SetKey(_TRACK_X, 0.28, 544.581085205078);
    effector:SetKey(_TRACK_Y, 0.28, 297.864868164063);
    effector:SetKey(_TRACK_X, 0.64, 561.081085205078);
    effector:SetKey(_TRACK_Y, 0.64, 319.364868164063);
    effector:SetKey(_TRACK_X, 0.96, 572.581085205078);
    effector:SetKey(_TRACK_Y, 0.96, 345.364868164063);
    effector:SetKey(_TRACK_X, 1.28, 569.581085205078);
    effector:SetKey(_TRACK_Y, 1.28, 368.364868164063);
    effector:SetKey(_TRACK_X, 1.68, 546.081085205078);
    effector:SetKey(_TRACK_Y, 1.68, 379.864868164063);
    effector:SetKey(_TRACK_X, 2.04, 506.081085205078);
    effector:SetKey(_TRACK_Y, 2.04, 370.864868164063);
    effector:SetKey(_TRACK_X, 2.44, 461.581085205078);
    effector:SetKey(_TRACK_Y, 2.44, 339.364868164063);
    effector:SetKey(_TRACK_X, 2.76, 429.081085205078);
    effector:SetKey(_TRACK_Y, 2.76, 298.364868164063);
    effector:SetKey(_TRACK_X, 3.16, 407.081085205078);
    effector:SetKey(_TRACK_Y, 3.16, 235.864868164063);
    effector:SetKey(_TRACK_X, 3.64, 374.581085205078);
    effector:SetKey(_TRACK_Y, 3.64, 176.364868164063);
    effector:SetKey(_TRACK_X, 4.08, 322.081085205078);
    effector:SetKey(_TRACK_Y, 4.08, 128.864868164063);
    effector:SetKey(_TRACK_X, 4.4, 259.581085205078);
    effector:SetKey(_TRACK_Y, 4.4, 120.864868164063);
    effector:SetKey(_TRACK_X, 4.8, 188.581085205078);
    effector:SetKey(_TRACK_Y, 4.8, 141.364868164063);
    effector:SetKey(_TRACK_X, 5.12, 147.081085205078);
    effector:SetKey(_TRACK_Y, 5.12, 191.864868164063);
    effector:SetKey(_TRACK_X, 5.52, 158.581085205078);
    effector:SetKey(_TRACK_Y, 5.52, 256.364868164063);
    effector:SetKey(_TRACK_X, 5.96, 212.581085205078);
    effector:SetKey(_TRACK_Y, 5.96, 300.364868164063);
    effector:SetKey(_TRACK_X, 6.36, 287.581085205078);
    effector:SetKey(_TRACK_Y, 6.36, 287.364868164063);
    effector:SetKey(_TRACK_X, 6.64, 319.581085205078);
    effector:SetKey(_TRACK_Y, 6.64, 246.864868164063);
    effector:SetKey(_TRACK_X, 6.96, 305.081085205078);
    effector:SetKey(_TRACK_Y, 6.96, 177.864868164063);
    effector:SetKey(_TRACK_X, 7.32, 250.581085205078);
    effector:SetKey(_TRACK_Y, 7.32, 139.864868164063);
    effector:SetKey(_TRACK_X, 7.6, 179.081085205078);
    effector:SetKey(_TRACK_Y, 7.6, 111.864868164063);
    effector:SetKey(_TRACK_X, 7.88, 166.081085205078);
    effector:SetKey(_TRACK_Y, 7.88, 105.364868164063);
    effector:SetKey(_TRACK_X, 8.16, 166.081085205078);
    effector:SetKey(_TRACK_Y, 8.16, 105.364868164063);
    effector:SetKey(_TRACK_X, 8.4, 215.581085205078);
    effector:SetKey(_TRACK_Y, 8.4, 87.8648681640625);
    effector:SetKey(_TRACK_X, 8.72, 215.581085205078);
    effector:SetKey(_TRACK_Y, 8.72, 87.8648681640625);
    effector:SetKey(_TRACK_X, 9, 168.581085205078);
    effector:SetKey(_TRACK_Y, 9, 80.3648681640625);
    effector:SetKey(_TRACK_X, 9.28, 116.081085205078);
    effector:SetKey(_TRACK_Y, 9.28, 102.364868164063);
    effector:SetKey(_TRACK_X, 9.56, 78.0810852050781);
    effector:SetKey(_TRACK_Y, 9.56, 144.864868164063);
    effector:SetKey(_TRACK_X, 9.76, 40.5810852050781);
    effector:SetKey(_TRACK_Y, 9.76, 187.864868164063);
    effector:SetKey(_TRACK_X, 9.96, -21.9189147949219);
    effector:SetKey(_TRACK_Y, 9.96, 221.864868164063);
    effector:SetKey(_TRACK_SX, 0, 0.6);
    effector:SetKey(_TRACK_SY, 0, 0.6);
    effector:SetKey(_TRACK_SX, 4, 1);
    effector:SetKey(_TRACK_SY, 4, 1);
    effector:SetKey(_TRACK_SX, 5.76, 1.2);
    effector:SetKey(_TRACK_SY, 5.76, 1.2);
    effector:SetKey(_TRACK_SX, 7.72, 1);
    effector:SetKey(_TRACK_SY, 7.72, 1);
    effector:SetKey(_TRACK_SX, 9.96, 1.2);
    effector:SetKey(_TRACK_SY, 9.96, 1.2);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 0.16, 0);
    effector:SetKey(_TRACK_O, 0.24, 1);
    effector:SetKey(_TRACK_O, 9.96, 1);

    effector:Play();

    compositionFly2:Play();

    return compositionFly2;
end

createCompositionSpider2 = function()

    local compositionSpider2 = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionSpider2:SetDuration(compositionDuration);


    -- Layer spider
    local element = auxCreateCompositionElement('data/Texture/Scenes/12_ShamansHut/Animations/Env/[01-10].png');
    element:SetName('spider');
    compositionSpider2:AddElement(element);
    element:SetHotSpot(36.0247344970703, 80.4063720703125);
    element:SetParentElement(compositionSpider2);
    element:SetScaleX(0.6);
    element:SetScaleY(0.6);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(5.32, 9.08);

    effector:SetKey(_TRACK_X, 0, 1040.18919372559);
    effector:SetKey(_TRACK_Y, 0, -61.8108062744141);
    effector:SetKey(_TRACK_X, 5.32, 1040.18919372559);
    effector:SetKey(_TRACK_Y, 5.32, -59.8108062744141);
    effector:SetKey(_TRACK_X, 5.68, 959.189193725586);
    effector:SetKey(_TRACK_Y, 5.68, -18.8108062744141);
    effector:SetKey(_TRACK_X, 6.04, 858.189193725586);
    effector:SetKey(_TRACK_Y, 6.04, 10.1891937255859);
    effector:SetKey(_TRACK_X, 6.48, 740.189193725586);
    effector:SetKey(_TRACK_Y, 6.48, 36.1891937255859);
    effector:SetKey(_TRACK_X, 6.96, 622.189193725586);
    effector:SetKey(_TRACK_Y, 6.96, 51.1891937255859);
    effector:SetKey(_TRACK_X, 7.44, 484.189193725586);
    effector:SetKey(_TRACK_Y, 7.44, 57.1891937255859);
    effector:SetKey(_TRACK_X, 7.88, 351.189193725586);
    effector:SetKey(_TRACK_Y, 7.88, 53.1891937255859);
    effector:SetKey(_TRACK_X, 8.36, 213.189193725586);
    effector:SetKey(_TRACK_Y, 8.36, 39.1891937255859);
    effector:SetKey(_TRACK_X, 8.6, 147.189193725586);
    effector:SetKey(_TRACK_Y, 8.6, 23.1891937255859);
    effector:SetKey(_TRACK_X, 8.8, 122.189193725586);
    effector:SetKey(_TRACK_Y, 8.8, -7.81080627441406);
    effector:SetKey(_TRACK_X, 9, 110.189193725586);
    effector:SetKey(_TRACK_Y, 9, -77.8108062744141);
    effector:SetKey(_TRACK_A, 5.32, -3.24993360516213);
    effector:SetKey(_TRACK_A, 6.84, -2.63068208200179);
    effector:SetKey(_TRACK_A, 8.6, -2.30898298296795);
    effector:SetKey(_TRACK_A, 8.8, -1.77456975611183);
    effector:SetKey(_TRACK_A, 9, -1.66228640785835);

    effector:Play();

    compositionSpider2:Play();

    return compositionSpider2;
end
