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

--// 1.	rename:					" -> '
--// 2. comment root composition routine 'createCompositionbackground = function()'
--// 5. add auxiliaru routines for managing animations: 
--		auxPlayOutOfCaveAnimation(), 
--		auxGetOutOfCaveAnimation(), 
--		auxCreateOutOfCaveAnimations()

------------------------------------------------------------------------------
--
function auxPlayOutOfCaveAnimation(compositionName)
    local composition = auxGetOutOfCaveAnimation(compositionName);
    composition:SetVisible(true);
    composition:Play();
end

------------------------------------------------------------------------------
--
function auxHideOutOfCaveAnimation(compositionName)
    local composition = auxGetOutOfCaveAnimation(compositionName);
    composition:Stop();
    composition:SetVisible(false);
end

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

    return outOfCaveCompositions[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 auxCreateOutOfCaveAnimations(parent)
    assert(parent ~= nil);
    outOfCaveCompositions = {};
    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);
        outOfCaveCompositions[element:GetName()] = element;
    end
    
    CreateAndRegisterComposition(parent, createCompositionDragonfly1,  		'Dragonfly1',		0,0,	110.0, 512,384, 10,		true);
    CreateAndRegisterComposition(parent, createCompositionCyclicCompGroup,	'CyclicCompGroup',  0,0,	100.0, 512,384, 8.04,	true);
    CreateAndRegisterComposition(parent, createCompositionPter_All1, 		'Pter_All1',  		125,100, 98.0, 512,384, 30, 	false);
    CreateAndRegisterComposition(parent, createCompositionPter_All1, 		'Pter_All2',  		180,120, 98.0, 512,384, 30, 	false);
end

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

    --// set up dragonfly animation
	if (texName == 'DF1_[0000-0004].png') then
		local anim = element:GetTexture();
		anim:Stop();
		anim:SetTextureRect(0,0, 128,96);
		anim:SetFrames(5);
		anim:SetFrame(0);
		anim:SetSpeed(30.0);
		anim:SetMode(HGEANIM_FWD + HGEANIM_LOOP);
		anim:Play();
    end
    --// set up pterodactyl animation
	if (texName == 'pter2_[0000-0029].png') then
		local anim = element:GetTexture();
		anim:Stop();
		anim:SetTextureRect(0,0, 77,36);
		anim:SetFrames(30);
		anim:SetFrame(0);
		anim:SetSpeed(8.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 == 'EF_Blink_glass01.jpg' or 
		texName == 'EF_Light01.jpg' or 
		texName == 'EF_Light02.jpg') then

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

------------------------------------------------------------------------------
--
--createCompositionbackground = function()
--
--    local compositionbackground = CreateCompositionSequence();
--    local compositionDuration = 10;
--    compositionbackground:SetDuration(compositionDuration);
--
--
--    -- Layer Layer_1
--    local element = createCompositionDragonfly1();
--    element:SetName('Layer_1');
--    compositionbackground:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionbackground);
--    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 = createCompositionCyclicCompGroup();
--    element:SetName('Layer_2');
--    compositionbackground:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionbackground);
--    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 = createCompositionPter_All1();
--    element:SetName('Layer_3');
--    compositionbackground:AddElement(element);
--    element:SetHotSpot(80, 384);
--    element:SetParentElement(compositionbackground);
--    element:SetXY(108, 464);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 30);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_4
--    local element = CreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/background.jpg');
--    element:SetName('Layer_4');
--    compositionbackground:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(compositionbackground);
--    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();
--
--    compositionbackground:Play();
--
--    return compositionbackground;
--end

createCompositionCyclicCompGroup = function()

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


    -- Layer Layer_1
    local element = createCompositiondust_fallComp();
    element:SetName('Layer_1');
    compositionCyclicCompGroup:AddElement(element);
    element:SetHotSpot(512, 384);
    element:SetParentElement(compositionCyclicCompGroup);
    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 = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/EF_Light02.jpg');
    element:SetName('Layer_2');
    compositionCyclicCompGroup:AddElement(element);
    element:SetHotSpot(64, 113);
    element:SetParentElement(compositionCyclicCompGroup);
    element:SetXY(302.362701416016, 358.020736694336);

    element:SetAngle(-0.46199911146172);

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

    effector:SetKey(_TRACK_SX, 0, 9.5931952141786);
    effector:SetKey(_TRACK_SY, 0, 5.82558381936323);
    effector:SetKey(_TRACK_SX, 1.12, 7.93076699185072);
    effector:SetKey(_TRACK_SY, 1.12, 6.04876424454111);
    effector:SetKey(_TRACK_SX, 2.28, 9.36986518148716);
    effector:SetKey(_TRACK_SY, 2.28, 5.92077588189661);
    effector:SetKey(_TRACK_SX, 3.56, 8.34968359141479);
    effector:SetKey(_TRACK_SY, 3.56, 5.92964368319888);
    effector:SetKey(_TRACK_SX, 6.48, 7.53913308939203);
    effector:SetKey(_TRACK_SY, 6.48, 5.93831575973788);
    effector:SetKey(_TRACK_SX, 7.6, 8.50405813218343);
    effector:SetKey(_TRACK_SY, 7.6, 6.15112782709513);
    effector:SetKey(_TRACK_SX, 9.96, 9.5931952141786);
    effector:SetKey(_TRACK_SY, 9.96, 5.82558381936323);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 0.56, 0.2);
    effector:SetKey(_TRACK_O, 1.12, 0);
    effector:SetKey(_TRACK_O, 1.96, 0.4);
    effector:SetKey(_TRACK_O, 2.64, 0.1);
    effector:SetKey(_TRACK_O, 3.6, 0.4);
    effector:SetKey(_TRACK_O, 4.4, 0);
    effector:SetKey(_TRACK_O, 5.36, 0.2);
    effector:SetKey(_TRACK_O, 5.8, 0.05);
    effector:SetKey(_TRACK_O, 6.48, 0.4);
    effector:SetKey(_TRACK_O, 7.44, 0.2);
    effector:SetKey(_TRACK_O, 8, 0.1);
    effector:SetKey(_TRACK_O, 8.6, 0.25);
    effector:SetKey(_TRACK_O, 9.96, 0);

    effector:Play();


    -- Layer Layer_3
    local element = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/EF_Blink_glass01.jpg');
    element:SetName('Layer_3');
    compositionCyclicCompGroup:AddElement(element);
    element:SetHotSpot(10, 4.5);
    element:SetParentElement(compositionCyclicCompGroup);

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

    effector:SetKey(_TRACK_X, 0, 460.982147216797);
    effector:SetKey(_TRACK_Y, 0, 588.165237426758);
    effector:SetKey(_TRACK_X, 0.36, 456.732147216797);
    effector:SetKey(_TRACK_Y, 0.36, 564.790237426758);
    effector:SetKey(_TRACK_X, 0.44, 456.482147216797);
    effector:SetKey(_TRACK_Y, 0.44, 560.165237426758);
    effector:SetKey(_TRACK_X, 0.8, 465.857147216797);
    effector:SetKey(_TRACK_Y, 0.8, 545.040237426758);
    effector:SetKey(_TRACK_X, 0.88, 495.607147216797);
    effector:SetKey(_TRACK_Y, 0.88, 584.790237426758);
    effector:SetKey(_TRACK_X, 1.7605859375, 502.232147216797);
    effector:SetKey(_TRACK_Y, 1.7605859375, 537.790237426758);
    effector:SetKey(_TRACK_X, 2.6, 469.857147216797);
    effector:SetKey(_TRACK_Y, 2.6, 588.415237426758);
    effector:SetKey(_TRACK_X, 3.12, 469.982147216797);
    effector:SetKey(_TRACK_Y, 3.12, 562.915237426758);
    effector:SetKey(_TRACK_X, 5.16, 480.732147216797);
    effector:SetKey(_TRACK_Y, 5.16, 586.790237426758);
    effector:SetKey(_TRACK_X, 5.92, 482.732147216797);
    effector:SetKey(_TRACK_Y, 5.92, 560.915237426758);
    effector:SetKey(_TRACK_X, 6.12, 502.107147216797);
    effector:SetKey(_TRACK_Y, 6.12, 581.040237426758);
    effector:SetKey(_TRACK_X, 6.88, 515.482147216797);
    effector:SetKey(_TRACK_Y, 6.88, 540.415237426758);
    effector:SetKey(_TRACK_X, 8.48, 469.857147216797);
    effector:SetKey(_TRACK_Y, 8.48, 588.415237426758);
    effector:SetKey(_TRACK_X, 9, 469.982147216797);
    effector:SetKey(_TRACK_Y, 9, 562.915237426758);
    effector:SetKey(_TRACK_SX, 0, 0.42260710400212);
    effector:SetKey(_TRACK_SY, 0, 0.21858408459688);
    effector:SetKey(_TRACK_SX, 0.12, 0.68494472897118);
    effector:SetKey(_TRACK_SY, 0.12, 0.7802041556246);
    effector:SetKey(_TRACK_SX, 0.4, 0.80809636623109);
    effector:SetKey(_TRACK_SY, 0.4, 0.25615637016193);
    effector:SetKey(_TRACK_SX, 0.56, 0.74383544292277);
    effector:SetKey(_TRACK_SY, 0.56, 0.40615931097819);
    effector:SetKey(_TRACK_SX, 0.64, 0.66446939656992);
    effector:SetKey(_TRACK_SY, 0.64, 0.64137801815239);
    effector:SetKey(_TRACK_SX, 0.8, 0.51854920024471);
    effector:SetKey(_TRACK_SY, 0.8, 0.01610639364389);
    effector:SetKey(_TRACK_SX, 0.88, 0.51854920024471);
    effector:SetKey(_TRACK_SY, 0.88, 0.01610639364389);
    effector:SetKey(_TRACK_SX, 1.28, 0.60188341673091);
    effector:SetKey(_TRACK_SY, 1.28, 0.97150395145818);
    effector:SetKey(_TRACK_SX, 1.76, 0.44175374018338);
    effector:SetKey(_TRACK_SY, 1.76, -0.22818910988621);
    effector:SetKey(_TRACK_SX, 2.6, 0.64380056407248);
    effector:SetKey(_TRACK_SY, 2.6, -0.10007976328776);
    effector:SetKey(_TRACK_SX, 2.8, 0.84269322757427);
    effector:SetKey(_TRACK_SY, 2.8, -0.87179569133749);
    effector:SetKey(_TRACK_SX, 3.08, 0.89012575010305);
    effector:SetKey(_TRACK_SY, 3.08, -0.38224358661087);
    effector:SetKey(_TRACK_SX, 3.16, 0.93021234648861);
    effector:SetKey(_TRACK_SY, 3.16, -0.07831405619651);
    effector:SetKey(_TRACK_SX, 5.16, 0.33765505451249);
    effector:SetKey(_TRACK_SY, 5.16, -0.11563850792209);
    effector:SetKey(_TRACK_SX, 5.36, 0.64743065543209);
    effector:SetKey(_TRACK_SY, 5.36, -0.75309371491251);
    effector:SetKey(_TRACK_SX, 5.92, 0.41305846386989);
    effector:SetKey(_TRACK_SY, 5.92, -0.2181218906709);
    effector:SetKey(_TRACK_SX, 6.12, 0.41305846386989);
    effector:SetKey(_TRACK_SY, 6.12, -0.2181218906709);
    effector:SetKey(_TRACK_SX, 6.28, 0.55632767998089);
    effector:SetKey(_TRACK_SY, 6.28, -0.82043982753941);
    effector:SetKey(_TRACK_SX, 6.88, 0.75872647918066);
    effector:SetKey(_TRACK_SY, 6.88, -0.09300716423594);
    effector:SetKey(_TRACK_SX, 8.48, 0.64380056407248);
    effector:SetKey(_TRACK_SY, 8.48, -0.10007976328776);
    effector:SetKey(_TRACK_SX, 8.68, 0.84269322757427);
    effector:SetKey(_TRACK_SY, 8.68, -0.87179569133749);
    effector:SetKey(_TRACK_SX, 8.96, 0.89012575010305);
    effector:SetKey(_TRACK_SY, 8.96, -0.38224358661087);
    effector:SetKey(_TRACK_SX, 9.04, 0.93021234648861);
    effector:SetKey(_TRACK_SY, 9.04, -0.07831405619651);
    effector:SetKey(_TRACK_A, 0, 0.60251556003866);
    effector:SetKey(_TRACK_A, 0.52, 0.26426667848302);
    effector:SetKey(_TRACK_A, 0.68, -0.25698381889799);
    effector:SetKey(_TRACK_A, 0.88, -0.25698381889799);
    effector:SetKey(_TRACK_A, 1.662734375, -0.42040365503875);
    effector:SetKey(_TRACK_A, 1.76, -0.17108097200965);
    effector:SetKey(_TRACK_A, 2.6, -0.37592988149109);
    effector:SetKey(_TRACK_A, 5.16, 0.40701591811312);
    effector:SetKey(_TRACK_A, 5.92, 0.40701591811312);
    effector:SetKey(_TRACK_A, 6.12, -0.34164567059088);
    effector:SetKey(_TRACK_A, 6.88, -0.12576079660415);
    effector:SetKey(_TRACK_A, 8.48, -0.37592988149109);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 0.12, 1);
    effector:SetKey(_TRACK_O, 0.36, 1);
    effector:SetKey(_TRACK_O, 0.72, 1);
    effector:SetKey(_TRACK_O, 0.8, 0);
    effector:SetKey(_TRACK_O, 0.88, 0);
    effector:SetKey(_TRACK_O, 1.075703125, 1);
    effector:SetKey(_TRACK_O, 1.72, 1);
    effector:SetKey(_TRACK_O, 1.76, 0);
    effector:SetKey(_TRACK_O, 2.6, 0);
    effector:SetKey(_TRACK_O, 2.68, 1);
    effector:SetKey(_TRACK_O, 3.12, 1);
    effector:SetKey(_TRACK_O, 3.16, 0);
    effector:SetKey(_TRACK_O, 5.16, 0);
    effector:SetKey(_TRACK_O, 5.24, 1);
    effector:SetKey(_TRACK_O, 5.88, 1);
    effector:SetKey(_TRACK_O, 5.92, 0);
    effector:SetKey(_TRACK_O, 6.12, 0);
    effector:SetKey(_TRACK_O, 6.16, 1);
    effector:SetKey(_TRACK_O, 6.88, 1);
    effector:SetKey(_TRACK_O, 6.92, 0);
    effector:SetKey(_TRACK_O, 8.48, 0);
    effector:SetKey(_TRACK_O, 8.56, 1);
    effector:SetKey(_TRACK_O, 9, 1);
    effector:SetKey(_TRACK_O, 9.04, 0);

    effector:Play();


    -- Layer Layer_4
    local element = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/EF_Light01.jpg');
    element:SetName('Layer_4');
    compositionCyclicCompGroup:AddElement(element);
    element:SetHotSpot(64, 54.5);
    element:SetParentElement(compositionCyclicCompGroup);
    element:SetXY(467.5, 547.5);

    element:SetScaleX(1.4375);
    element:SetScaleY(1.75229357798165);
    element:SetAngle(0);

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

    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 0.84, 0.4);
    effector:SetKey(_TRACK_O, 1.28, 0.1);
    effector:SetKey(_TRACK_O, 1.84, 0.2);
    effector:SetKey(_TRACK_O, 2.52, 0.05);
    effector:SetKey(_TRACK_O, 3.2, 0.3);
    effector:SetKey(_TRACK_O, 3.48, 0.09999999569444);
    effector:SetKey(_TRACK_O, 3.96, 0.25000000442888);
    effector:SetKey(_TRACK_O, 4.56, 0.32941783259595);
    effector:SetKey(_TRACK_O, 4.92, 0.25000000442888);
    effector:SetKey(_TRACK_O, 5.52, 0.4572307804988);
    effector:SetKey(_TRACK_O, 6.36, 0.2);
    effector:SetKey(_TRACK_O, 6.64, 0.53932308819111);
    effector:SetKey(_TRACK_O, 7.4, 0.39999998868607);
    effector:SetKey(_TRACK_O, 7.8, 0.1);
    effector:SetKey(_TRACK_O, 8.28, 0.25);
    effector:SetKey(_TRACK_O, 9, 0.05);
    effector:SetKey(_TRACK_O, 9.4, 0.1);
    effector:SetKey(_TRACK_O, 9.96, 0);

    effector:Play();


    -- Layer Layer_5
    local element = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/Layer_over_dino01.png');
    element:SetName('Layer_5');
    compositionCyclicCompGroup:AddElement(element);
    element:SetHotSpot(60, 55);
    element:SetParentElement(compositionCyclicCompGroup);
    element:SetXY(623.121765136719, 300.966323852539);

    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 = createCompositionFlyDino();
    element:SetName('Layer_6');
    compositionCyclicCompGroup:AddElement(element);
    element:SetHotSpot(512, 384);
    element:SetParentElement(compositionCyclicCompGroup);
    element:SetXY(512, 384);

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

    effector = element:GetEffector();
    effector:SetLifeTime(3.92, 6.92);


    effector:Play();

    compositionCyclicCompGroup:Play();

    return compositionCyclicCompGroup;
end

createCompositionDragonfly1 = function()

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


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/DF1_[0000-0004].png');
    element:SetName('Layer_1');
    compositionDragonfly1:AddElement(element);
    element:SetHotSpot(64, 48);
    element:SetParentElement(compositionDragonfly1);
    element:SetOpacity(1);

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

    effector:SetKey(_TRACK_X, 0, 1104.91191101074);
    effector:SetKey(_TRACK_Y, 0, 635.357513427734);
    effector:SetKey(_TRACK_X, 0.08, 1023.13265531479);
    effector:SetKey(_TRACK_Y, 0.08, 640.881450568142);
    effector:SetKey(_TRACK_X, 0.2, 938.588174824401);
    effector:SetKey(_TRACK_Y, 0.2, 620.039085255626);
    effector:SetKey(_TRACK_X, 0.36, 884.906539563455);
    effector:SetKey(_TRACK_Y, 0.36, 594.650515929422);
    effector:SetKey(_TRACK_X, 0.52, 868.635393952163);
    effector:SetKey(_TRACK_Y, 0.52, 579.917831596522);
    effector:SetKey(_TRACK_X, 0.76, 854.21760559082);
    effector:SetKey(_TRACK_Y, 0.76, 557.098449707031);
    effector:SetKey(_TRACK_X, 2.04, 854.21760559082);
    effector:SetKey(_TRACK_Y, 2.04, 557.098449707031);
    effector:SetKey(_TRACK_X, 2.16, 874.71760559082);
    effector:SetKey(_TRACK_Y, 2.16, 563.098449707031);
    effector:SetKey(_TRACK_X, 2.24, 897.71760559082);
    effector:SetKey(_TRACK_Y, 2.24, 559.098449707031);
    effector:SetKey(_TRACK_X, 2.32, 918.71760559082);
    effector:SetKey(_TRACK_Y, 2.32, 540.098449707031);
    effector:SetKey(_TRACK_X, 2.44, 933.71760559082);
    effector:SetKey(_TRACK_Y, 2.44, 497.598449707031);
    effector:SetKey(_TRACK_X, 3.44, 933.71760559082);
    effector:SetKey(_TRACK_Y, 3.44, 497.598449707031);
    effector:SetKey(_TRACK_X, 3.52, 918.71760559082);
    effector:SetKey(_TRACK_Y, 3.52, 502.598449707031);
    effector:SetKey(_TRACK_X, 3.64, 890.21760559082);
    effector:SetKey(_TRACK_Y, 3.64, 506.598449707031);
    effector:SetKey(_TRACK_X, 3.76, 807.077713012695);
    effector:SetKey(_TRACK_Y, 3.76, 495.466323852539);
    effector:SetKey(_TRACK_X, 3.88, 709.326416015625);
    effector:SetKey(_TRACK_Y, 3.88, 469.049224853516);
    effector:SetKey(_TRACK_X, 4, 592.158020019531);
    effector:SetKey(_TRACK_Y, 4, 433.132125854492);
    effector:SetKey(_TRACK_X, 4.24, 465.386001586914);
    effector:SetKey(_TRACK_Y, 4.24, 383.97151184082);
    effector:SetKey(_TRACK_X, 4.72, 233.419677734375);
    effector:SetKey(_TRACK_Y, 4.72, 224.981872558594);
    effector:SetKey(_TRACK_X, 6, 233.419677734375);
    effector:SetKey(_TRACK_Y, 6, 224.981872558594);
    effector:SetKey(_TRACK_X, 6.12, 257.295318603516);
    effector:SetKey(_TRACK_Y, 6.12, 228.961151123047);
    effector:SetKey(_TRACK_X, 6.24, 288.795318603516);
    effector:SetKey(_TRACK_Y, 6.24, 221.961151123047);
    effector:SetKey(_TRACK_X, 6.36, 334.295318603516);
    effector:SetKey(_TRACK_Y, 6.36, 192.961151123047);
    effector:SetKey(_TRACK_X, 8.08, 334.295318603516);
    effector:SetKey(_TRACK_Y, 8.08, 192.961151123047);
    effector:SetKey(_TRACK_X, 8.2, 310.295318603516);
    effector:SetKey(_TRACK_Y, 8.2, 199.461151123047);
    effector:SetKey(_TRACK_X, 8.32, 269.295318603516);
    effector:SetKey(_TRACK_Y, 8.32, 194.461151123047);
    effector:SetKey(_TRACK_X, 8.48, 215.295318603516);
    effector:SetKey(_TRACK_Y, 8.48, 177.461151123047);
    effector:SetKey(_TRACK_X, 8.8, 124.295318603516);
    effector:SetKey(_TRACK_Y, 8.8, 100.461151123047);
    effector:SetKey(_TRACK_X, 9.04, 88.2953186035156);
    effector:SetKey(_TRACK_Y, 9.04, 30.4611511230469);
    effector:SetKey(_TRACK_X, 9.28, 54.6631927490234);
    effector:SetKey(_TRACK_Y, 9.28, -89.3937683105469);
    effector:SetKey(_TRACK_SX, 0, 2);
    effector:SetKey(_TRACK_SY, 0, 2);
    effector:SetKey(_TRACK_SX, 0.76, 1);
    effector:SetKey(_TRACK_SY, 0.76, 1);
    effector:SetKey(_TRACK_SX, 2.04, 1);
    effector:SetKey(_TRACK_SY, 2.04, 1);
    effector:SetKey(_TRACK_SX, 2.44, 0.8);
    effector:SetKey(_TRACK_SY, 2.44, 0.8);
    effector:SetKey(_TRACK_SX, 3.44, 0.8);
    effector:SetKey(_TRACK_SY, 3.44, 0.8);
    effector:SetKey(_TRACK_SX, 4.72, 0.5);
    effector:SetKey(_TRACK_SY, 4.72, 0.5);
    effector:SetKey(_TRACK_SX, 6, 0.5);
    effector:SetKey(_TRACK_SY, 6, 0.5);
    effector:SetKey(_TRACK_SX, 6.36, 0.6);
    effector:SetKey(_TRACK_SY, 6.36, 0.6);
    effector:SetKey(_TRACK_SX, 8.08, 0.6);
    effector:SetKey(_TRACK_SY, 8.08, 0.6);
    effector:SetKey(_TRACK_SX, 9.28, 1);
    effector:SetKey(_TRACK_SY, 9.28, 1);
    effector:SetKey(_TRACK_A, 0, -0.31418637558308);
    effector:SetKey(_TRACK_A, 0.76, 0.14523690313184);
    effector:SetKey(_TRACK_A, 0.84, 0.37993912127976);
    effector:SetKey(_TRACK_A, 1, -0.00072160445983);
    effector:SetKey(_TRACK_A, 1.6, 0.14202995892963);
    effector:SetKey(_TRACK_A, 2.04, 0.0482822761817);
    effector:SetKey(_TRACK_A, 2.32, 0.43147289564102);
    effector:SetKey(_TRACK_A, 2.48, -0.25460477378904);
    effector:SetKey(_TRACK_A, 2.68, -0.14609122362212);
    effector:SetKey(_TRACK_A, 2.96, 0.02879487470463);
    effector:SetKey(_TRACK_A, 3.44, -0.34118461067165);
    effector:SetKey(_TRACK_A, 3.92, -0.23022607290395);
    effector:SetKey(_TRACK_A, 4.72, -0.11985915270867);
    effector:SetKey(_TRACK_A, 4.88, 0.18645939074675);
    effector:SetKey(_TRACK_A, 5.12, -0.23125891652683);
    effector:SetKey(_TRACK_A, 6, -0.18411797272986);
    effector:SetKey(_TRACK_A, 6.12, 0.13192743586137);
    effector:SetKey(_TRACK_A, 6.36, 0.07002883758554);
    effector:SetKey(_TRACK_A, 6.44, -0.39673370907614);
    effector:SetKey(_TRACK_A, 6.72, -0.05590099470781);
    effector:SetKey(_TRACK_A, 7.28, -0.28346678271317);
    effector:SetKey(_TRACK_A, 8.08, -0.46973423861689);
    effector:SetKey(_TRACK_A, 8.28, -0.17871795346108);
    effector:SetKey(_TRACK_A, 8.6, -0.48885744073049);
    effector:SetKey(_TRACK_A, 9.28, -0.60760389673433);

    effector:Play();

    compositionDragonfly1:Play();

    return compositionDragonfly1;
end

createCompositiondust_fallComp = function()

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


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/dust_fall01.png');
    element:SetName('Layer_1');
    compositiondust_fallComp:AddElement(element);
    element:SetHotSpot(32, 32);
    element:SetParentElement(compositiondust_fallComp);

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

    effector:SetKey(_TRACK_X, 0, 482);
    effector:SetKey(_TRACK_Y, 0, -126);
    effector:SetKey(_TRACK_X, 0.6, 483.799999701977);
    effector:SetKey(_TRACK_Y, 0.6, 64.579247669389);
    effector:SetKey(_TRACK_X, 1.32, 448);
    effector:SetKey(_TRACK_Y, 1.32, 218);
    effector:SetKey(_TRACK_X, 2.2, 154.373046875);
    effector:SetKey(_TRACK_Y, 2.2, -98.1450805664063);
    effector:SetKey(_TRACK_X, 2.8, 154.846615302563);
    effector:SetKey(_TRACK_Y, 2.8, 104.371987537553);
    effector:SetKey(_TRACK_X, 3.52, 133.637298583984);
    effector:SetKey(_TRACK_Y, 3.52, 272.383422851563);
    effector:SetKey(_TRACK_SX, 0, 3.25);
    effector:SetKey(_TRACK_SY, 0, 2.9375);
    effector:SetKey(_TRACK_SX, 1.32, 4.66670386809863);
    effector:SetKey(_TRACK_SY, 1.32, 4.72920386809863);
    effector:SetKey(_TRACK_SX, 2.2, 2.58678756476684);
    effector:SetKey(_TRACK_SY, 2.2, 2.68879533678757);
    effector:SetKey(_TRACK_SX, 3.52, 4.66670386809863);
    effector:SetKey(_TRACK_SY, 3.52, 4.72920386809863);
    effector:SetKey(_TRACK_A, 0, 0);
    effector:SetKey(_TRACK_A, 1.32, 0.7853981625);
    effector:SetKey(_TRACK_A, 2.2, 0);
    effector:SetKey(_TRACK_A, 3.52, 0.7853981625);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 0.32, 1);
    effector:SetKey(_TRACK_O, 1.32, 0);
    effector:SetKey(_TRACK_O, 2.2, 0);
    effector:SetKey(_TRACK_O, 2.52, 1);
    effector:SetKey(_TRACK_O, 3.52, 0);

    effector:Play();

    compositiondust_fallComp:Play();

    return compositiondust_fallComp;
end

createCompositionFlyDino = function()

    local compositionFlyDino = CreateCompositionSequence();
    local compositionDuration = 3;
    compositionFlyDino:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/Layer_dino2head.png');
    element:SetName('Layer_1');
    compositionFlyDino:AddElement(element);
    element:SetHotSpot(28.5, 29);
    compositionFlyDino:RegisterParentInfo('Layer_1', 'Layer_2');
    element:SetXY(7.5, 3.5);

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

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

    effector:SetKey(_TRACK_A, 0, -0.36743424149717);
    effector:SetKey(_TRACK_A, 0.24, 0.34555222420413);
    effector:SetKey(_TRACK_A, 0.36, 0.05097457482157);
    effector:SetKey(_TRACK_A, 0.76, 0.17372549317124);
    effector:SetKey(_TRACK_A, 1.04, 0.25666870314546);
    effector:SetKey(_TRACK_A, 1.44, 0.09187676956866);
    effector:SetKey(_TRACK_A, 1.96, -0.11818548876225);
    effector:SetKey(_TRACK_A, 2.16, 0.32856350818631);
    effector:SetKey(_TRACK_A, 2.72, -0.01895992375229);

    effector:Play();


    -- Layer Layer_2
    local element = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/Layer_dino2.png');
    element:SetName('Layer_2');
    compositionFlyDino:AddElement(element);
    element:SetHotSpot(29.5, 53);
    element:SetParentElement(compositionFlyDino);
    element:SetScaleX(0.6);
    element:SetScaleY(0.6);
    element:SetOpacity(1);

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

    effector:SetKey(_TRACK_X, 0, 625);
    effector:SetKey(_TRACK_Y, 0, 314);
    effector:SetKey(_TRACK_X, 0.08, 618.889778788103);
    effector:SetKey(_TRACK_Y, 0.08, 312.791176242426);
    effector:SetKey(_TRACK_X, 0.16, 613.073870074288);
    effector:SetKey(_TRACK_Y, 0.16, 310.618106655682);
    effector:SetKey(_TRACK_X, 0.24, 608);
    effector:SetKey(_TRACK_Y, 0.24, 307);
    effector:SetKey(_TRACK_X, 2.4, 608);
    effector:SetKey(_TRACK_Y, 2.4, 307);
    effector:SetKey(_TRACK_X, 2.48, 613.001652691747);
    effector:SetKey(_TRACK_Y, 2.48, 310.312281261386);
    effector:SetKey(_TRACK_X, 2.6, 618.870337358844);
    effector:SetKey(_TRACK_Y, 2.6, 312.408685255291);
    effector:SetKey(_TRACK_X, 2.72, 625.125);
    effector:SetKey(_TRACK_Y, 2.72, 314.125);
    effector:SetKey(_TRACK_A, 0, 0);
    effector:SetKey(_TRACK_A, 0.24, -0.35086252527335);
    effector:SetKey(_TRACK_A, 0.36, -0.12849445965782);
    effector:SetKey(_TRACK_A, 0.52, -0.24565163493153);
    effector:SetKey(_TRACK_A, 1.2, -0.34702861148569);
    effector:SetKey(_TRACK_A, 1.96, -0.0984544403619);
    effector:SetKey(_TRACK_A, 2.16, -0.59013952789175);
    effector:SetKey(_TRACK_A, 2.72, 0.07482413903467);

    effector:Play();

    compositionFlyDino:Play();

    return compositionFlyDino;
end

createCompositionPter2 = function()

    local compositionPter2 = CreateCompositionSequence();
    local compositionDuration = 3.8;
    compositionPter2:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/05_OutOfCave/Animations/Env/pter2_[0000-0029].png');
    element:SetName('Layer_1');
    compositionPter2:AddElement(element);
    element:SetHotSpot(38.5, 18);
    element:SetParentElement(compositionPter2);
    element:SetAngle(0);
    element:SetOpacity(1);

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

    effector:SetKey(_TRACK_X, 0, 94.2752532958984);
    effector:SetKey(_TRACK_Y, 0, 31.2694244384766);
    effector:SetKey(_TRACK_X, 0.6, 77.2126947556644);
    effector:SetKey(_TRACK_Y, 0.6, 31.2694244384765);
    effector:SetKey(_TRACK_X, 1.3191015625, 45.1502532958984);
    effector:SetKey(_TRACK_Y, 1.3191015625, 31.2694244384766);
    effector:SetKey(_TRACK_X, 1.8474609375, 27.6502532958984);
    effector:SetKey(_TRACK_Y, 1.8474609375, 31.2694244384766);
    effector:SetKey(_TRACK_X, 2.4, 44.9002532958984);
    effector:SetKey(_TRACK_Y, 2.4, 31.2694244384766);
    effector:SetKey(_TRACK_X, 3.2, 77.4002532958984);
    effector:SetKey(_TRACK_Y, 3.2, 31.2694244384766);
    effector:SetKey(_TRACK_X, 3.8, 94.4002532958984);
    effector:SetKey(_TRACK_Y, 3.8, 31.2694244384766);
    effector:SetKey(_TRACK_SX, 0, 0.8);
    effector:SetKey(_TRACK_SY, 0, 0.8);
    effector:SetKey(_TRACK_SX, 0.6, 1);
    effector:SetKey(_TRACK_SY, 0.6, 1);
    effector:SetKey(_TRACK_SX, 0.96, 1.1);
    effector:SetKey(_TRACK_SY, 0.96, 1.1);
    effector:SetKey(_TRACK_SX, 1.3191015625, 1);
    effector:SetKey(_TRACK_SY, 1.3191015625, 1);
    effector:SetKey(_TRACK_SX, 1.8474609375, 0.8);
    effector:SetKey(_TRACK_SY, 1.8474609375, 0.8);
    effector:SetKey(_TRACK_SX, 2.4, 0.6);
    effector:SetKey(_TRACK_SY, 2.4, 0.6);
    effector:SetKey(_TRACK_SX, 2.84, 0.5);
    effector:SetKey(_TRACK_SY, 2.84, 0.5);
    effector:SetKey(_TRACK_SX, 3.2, 0.6);
    effector:SetKey(_TRACK_SY, 3.2, 0.6);
    effector:SetKey(_TRACK_SX, 3.8, 0.8);
    effector:SetKey(_TRACK_SY, 3.8, 0.8);

    effector:Play();

    compositionPter2:Play();

    return compositionPter2;
end

createCompositionPter_All1 = function()

    local compositionPter_All1 = CreateCompositionSequence();
    local compositionDuration = 30;
    compositionPter_All1:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = createCompositionPter2();
    element:SetName('Layer_1');
    compositionPter_All1:AddElement(element);
    element:SetHotSpot(64, 32);
    compositionPter_All1:RegisterParentInfo('Layer_1', 'Layer_2');
    element:SetXY(64, 32);

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

    effector = element:GetEffector();
    effector:SetLifeTime(26.68, 30.48);


    effector:Play();


    -- Layer Layer_2
    local element = createCompositionPter2();
    element:SetName('Layer_2');
    compositionPter_All1:AddElement(element);
    element:SetHotSpot(64, 32);
    compositionPter_All1:RegisterParentInfo('Layer_2', 'Layer_3');
    element:SetXY(64, 32);

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

    effector = element:GetEffector();
    effector:SetLifeTime(22.84, 26.64);


    effector:Play();


    -- Layer Layer_3
    local element = createCompositionPter2();
    element:SetName('Layer_3');
    compositionPter_All1:AddElement(element);
    element:SetHotSpot(64, 32);
    compositionPter_All1:RegisterParentInfo('Layer_3', 'Layer_4');
    element:SetXY(64, 32);

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

    effector = element:GetEffector();
    effector:SetLifeTime(19, 22.8);


    effector:Play();


    -- Layer Layer_4
    local element = createCompositionPter2();
    element:SetName('Layer_4');
    compositionPter_All1:AddElement(element);
    element:SetHotSpot(64, 32);
    compositionPter_All1:RegisterParentInfo('Layer_4', 'Layer_5');
    element:SetXY(64, 32);

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

    effector = element:GetEffector();
    effector:SetLifeTime(15.2, 19);


    effector:Play();


    -- Layer Layer_5
    local element = createCompositionPter2();
    element:SetName('Layer_5');
    compositionPter_All1:AddElement(element);
    element:SetHotSpot(64, 32);
    compositionPter_All1:RegisterParentInfo('Layer_5', 'Layer_6');
    element:SetXY(64, 32);

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

    effector = element:GetEffector();
    effector:SetLifeTime(11.4, 15.2);


    effector:Play();


    -- Layer Layer_6
    local element = createCompositionPter2();
    element:SetName('Layer_6');
    compositionPter_All1:AddElement(element);
    element:SetHotSpot(64, 32);
    compositionPter_All1:RegisterParentInfo('Layer_6', 'Layer_7');
    element:SetXY(64, 32);

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

    effector = element:GetEffector();
    effector:SetLifeTime(7.6, 11.4);


    effector:Play();


    -- Layer Layer_7
    local element = createCompositionPter2();
    element:SetName('Layer_7');
    compositionPter_All1:AddElement(element);
    element:SetHotSpot(64, 32);
    compositionPter_All1:RegisterParentInfo('Layer_7', 'Layer_8');
    element:SetXY(64, 32);

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

    effector = element:GetEffector();
    effector:SetLifeTime(3.8, 7.6);


    effector:Play();


    -- Layer Layer_8
    local element = createCompositionPter2();
    element:SetName('Layer_8');
    compositionPter_All1:AddElement(element);
    element:SetHotSpot(64, 32);
    element:SetParentElement(compositionPter_All1);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);

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

    effector:SetKey(_TRACK_X, 0, 80);
    effector:SetKey(_TRACK_Y, 0, 152.997958612503);
    effector:SetKey(_TRACK_X, 29.96, 79);
    effector:SetKey(_TRACK_Y, 29.96, 513.997958612503);

    effector:Play();

    compositionPter_All1:Play();

    return compositionPter_All1;
end
