//Augment Module var ITW = (function(itw){ "use strict"; //aliases var components, protot; itw.components = itw.components || Object.create(null); components = itw.components; var SEA_HEIGHT = Object.create(null); components.BGFish = function(index){ if(typeof index === "undefined") index = Math.round(EHDI.NumberUtil.randomRange(1,2)); var _sprMain, _scaleFactor; this.super.call(this); this.spdMult = EHDI.NumberUtil.randomRange(0.4,0.6); var _self = this; Object.defineProperty(this, "scaleFactor", { set: function(val){ _scaleFactor = val; _self.scale.set(val, Math.abs(val)); }, get: function(){ return _scaleFactor; } }) var _init = function(){ var _scale; _sprMain = new EHDI.aka.Sprite(EHDI.Assets.images["bgfish" + index]); _self.addChild(_sprMain); _scale = EHDI.NumberUtil.randomRange(0.8,1.2); if(Math.random() > 0.5) _scale *= -1; _self.scaleFactor = _scale; _self.x = (_self.scaleFactor < 0) ? -_self.width : ITW.SceneMgr.getStageWidth(); _self.y = EHDI.NumberUtil.randomRange(SEA_HEIGHT.top, SEA_HEIGHT.bot); } _init(); } protot = components.BGFish.prototype = Object.create(EHDI.aka.Container.prototype); protot.constructor = components.BGFish; protot.super = EHDI.aka.Container; components.BGFish.setMaxHeight = function(top, bot){ SEA_HEIGHT.top = top; SEA_HEIGHT.bot = bot; } protot.loop = function( dt ){ var spd = dt * ( ITW.GameMgr.getSpeed() * this.spdMult ); this.x = (((this.scaleFactor < 0) ? 1 : -1 ) * spd) + this.x; if(this.x < -52 || this.x > ITW.SceneMgr.getStageWidth() + 52){ this.resetPos(); } } protot.resetPos = function(){ var _scale; _scale = EHDI.NumberUtil.randomRange(0.8,1.2); if(Math.random() > 0.5) _scale *= -1; this.spdMult = EHDI.NumberUtil.randomRange(0.4,0.6); this.scaleFactor = _scale; this.x = (this.scaleFactor < 0) ? -this.width : ITW.SceneMgr.getStageWidth(); this.y = EHDI.NumberUtil.randomRange(SEA_HEIGHT.top, SEA_HEIGHT.bot); } protot.destroy = function(){ this.super.prototype.destroy.call(this, {children: true}); } return itw; }(ITW || Object.create(null)))