//Augment Module var ITW = (function(itw){ "use strict"; //aliases var components, protot, _this, _super; itw.components = itw.components || Object.create(null); components = itw.components; var MAX_FISH = 6; //privates - initialize on constructor function var _skyContainer, _landContainer, _seabedContainer1, _seabedContainer2, _bgFishContainer; var _sky, _land, _underwater, _decomanager, _bgFishies, _seabed; components.Background = function(){ this.super.call(this); _this = this; _super = _this.super; var _init = function(){ // init stuff here var index = 0; _skyContainer = new EHDI.aka.Container(); for( index = 0; index < 2; index++ ){ var skyObj = new EHDI.aka.Sprite( EHDI.Assets.images[ "sky" ] ); _skyContainer.addChild( skyObj ); if( index === 1 ) skyObj.x = skyObj.width; } _landContainer = new EHDI.aka.Container(); for( index = 0; index < 2; index++ ){ var landObj = new EHDI.aka.Sprite( EHDI.Assets.images[ "terrain" ] ); _landContainer.addChild( landObj ); if( index === 1 ) landObj.x = landObj.width; } _underwater = new EHDI.aka.Sprite( EHDI.Assets.images[ "underwater" ] ); _underwater.y = ITW.SceneMgr.getStageHeight() - _underwater.height; // _decomanager = new ITW.managers.UnderwaterDecoManager(); _seabedContainer1 = new EHDI.aka.Container(); for( index = 0; index < 2; index++ ){ var seabedObj = new EHDI.aka.Sprite( EHDI.Assets.images[ "seabed1" ] ); _seabedContainer1.addChild( seabedObj ); if( index === 1 ) seabedObj.x = seabedObj.width; } _seabedContainer1.y = ITW.SceneMgr.getStageHeight() - _seabedContainer1.height; _seabedContainer2 = new EHDI.aka.Container(); for( index = 0; index < 2; index++ ){ var seabedObj = new EHDI.aka.Sprite( EHDI.Assets.images[ "seabed2" ] ); _seabedContainer2.addChild( seabedObj ); if( index === 1 ) seabedObj.x = seabedObj.width; } _seabedContainer2.y = ITW.SceneMgr.getStageHeight() - _seabedContainer2.height; if(!ITW.isIP4){ _bgFishContainer = new EHDI.aka.Container(); ITW.components.BGFish.setMaxHeight(ITW.SceneMgr.getStageHeight() * 0.34, _seabedContainer2.y - 40); _bgFishies = []; var type; for( index = 0; index < MAX_FISH; index++){ type = index % 2; _bgFishies[index] = new ITW.components.BGFish(type+1); _bgFishContainer.addChild(_bgFishies[index]) } } _seabed = new ITW.components.SeaBed(); _this.addChild( _skyContainer ); _this.addChild( _landContainer ); _this.addChild( _underwater ); if(_bgFishContainer)_this.addChild( _bgFishContainer ); _this.addChild( _seabed ); _landContainer.y = _underwater.y - _landContainer.height; _this.scale.x = 1.02; } _init(); } protot = components.Background.prototype = Object.create(EHDI.aka.Container.prototype); protot.constructor = components.Background; protot.super = EHDI.aka.Container; protot.loop = function( dt ){ if(!!ITW.GameMgr.getGameOver()) return; _skyContainer.x -= dt * ( ITW.GameMgr.getSpeed() * 0.15 ); if( _skyContainer.x <= _skyContainer.width * -0.5 ) _skyContainer.x += _skyContainer.width * 0.5; _landContainer.x -= dt * ( ITW.GameMgr.getSpeed() * 0.6 ); if( _landContainer.x <= _landContainer.width * -0.5 ) _landContainer.x += _landContainer.width * 0.5; if(_bgFishContainer) for(var i = 0, len = _bgFishies.length; i < len; i++) _bgFishies[i].loop( dt ); _seabed.loop( dt ); } protot.destroy = function(){ if(_bgFishContainer){ while(_bgFishies.length > 0){ var spr = _bgFishies.pop(); spr.destroy({children: true}); } } _super.prototype.destroy.call(this, {children: true}); } return itw; }(ITW || Object.create(null)));