var QyScene=window.QyScene=cc.Scene.extend({ctor:function(e){this._super();e||(e={});this._instances=[];qyengine.winSize=e.size;e.isPauseScene||this.isPauseScene()?this._pauseScene=!0:window.scene=window.current_scene=this;this.setBackground(e);this._qyobjects=[];this.setLayers(e);e.view?cc.view.setDesignResolutionSize(e.view.width,e.view.height,cc.ResolutionPolicy.SHOW_ALL):cc.view.setDesignResolutionSize(e.size.width,e.size.height,cc.ResolutionPolicy.SHOW_ALL);e.isPauseScene||e.view&&this.setView(e.view);this.followObj&&this.schedule(this.updateView,.01);this.schedule(this.update.bind(this),1/60)},steupDebugNode:function(){this._debugNode=new cc.PhysicsDebugNode(current_game.space);this._debugNode.visible=!0;this.addChild(this._debugNode)},setupWorld:function(e,t){this.createWorld(t)},createWorld:function(e){var t=e&&e.x||0,i=e&&e.y||0;this.gravity={x:t,y:i};if(current_game.space)current_game.space.gravity=this.gravity;else{current_game.space=new cp.Space;current_game.space.setDefaultCollisionHandler(this.collisionBegin.bind(this),this.collisionPre.bind(this),this.collisionPost.bind(this),this.collisionSeparate.bind(this))}return current_game.space},collisionBegin:function(){return!0},collisionPre:function(){return!0},collisionPost:function(){},collisionSeparate:function(){},addInstance:function(e){this._instances.push(e);return this},isPauseScene:function(){return this._pauseScene},setBackground:function(e){if(!e.background||"no-background"==e.background)return this;var t=qyengine.guardType(e.background);if(t){var i=new t(e);this.currentSprite=this.background=i.currentSprite||i;i.setAnchorPoint(0,0);i.bindObj=this;this.background.isBG=!0;this.addChild(this.background)}return this},setLayers:function(e){var t=e.layers;if(!t||0==t.length)return this;var i=t.length;this._qylayers=new Array(i);for(var s=0;i>s;s++){this._qylayers[s]=new QyLayer(t[s]);this.addChild(this._qylayers[s])}e.defaultLayer&&(this.defaultLayer=window[e.defaultLayer]);this.defaultLayer||(this.defaultLayer=this);for(s=0;i>s;s++)this.setOneLayer(this._qylayers[s],t[s]);return this},setOneLayer:function(e,t){if(t&&t.objects)for(var i=0;i<t.objects.length;i++){var s=t.objects[i];s.id||(s.id=s.type);s.sceneId=this.id;this._qyobjects.push(qyengine.createInstance(s,e,!1))}e.isVisible()||e.hide();return this},setView:function(e){this.view=e;e.x||(e.x=0);e.y||(e.y=0);e.width||(e.width=this.full_size.width);e.height||(e.height=this.full_size.height);this.setContentSize(e.width,e.height);this.background.setPosition(e.x,e.y-qyengine.winSize.height+e.height);qyengine.offsetLeft=e.x;qyengine.offsetTop=e.y-qyengine.winSize.height+e.height;for(var t=0;t<this._qylayers.length;t++)this._qylayers[t].setPosition(qyengine.offsetLeft,qyengine.offsetTop);e.follows&&this.setFollowView(e.follows);(0!==e.x||0!==e.y)&&this.viewAt(e.x,e.y)},setFollowView:function(e){this.view?this.followObj=e&&e.id||e:console.log("setting following obj but no view is set")},releaseFollowView:function(){this.followObj=null},updateView:function(){var e=cc.winSize;this.setCamera(qyengine.guardId(this.followObj).getPosition(),cc.size(e.width/2,e.height/2),this.background.getContentSize())},setCamera:function(e,t,i){{var s=this.background.getPosition();Math.abs(e.x- -s.x),Math.abs(e.y- -s.y)}if(e.x>t.width&&e.x<i.width-t.width){this.background.setPositionX(t.width-e.x);for(var n=0;n<this._qylayers.length;n++)this._qylayers[n].setPositionX(t.width-e.x);qyengine.offsetLeft=this.background.getPositionX()}if(e.y>t.height&&e.y<i.height-t.height){this.background.setPositionY(t.height-e.y);for(var n=0;n<this._qylayers.length;n++)this._qylayers[n].setPositionY(t.height-e.y);qyengine.offsetTop=this.background.getPositionY()}},update:function(){}});QyScene.prototype.setTimeline=function(e,t){this._qytimeline&&this._qytimeline.stop();e.classId&&(e=e.classId);var i=qyengine.guardType(e);if(i){this._qytimeline=new i(t);this._qytimeline.bindObj=this;t&&t.start&&this._qytimeline.start()}return this};QyScene.prototype.spriteListen=function(e,t){if(this.currentSprite){"touchstart"===e&&this.currentSprite.touchListen&&this.currentSprite.touchListen(e,t);this.eventHandlers||(this.eventHandlers={});this.eventHandlers[e]=t}return this};QyScene.prototype.objListen=function(e,t,i){this.eventHandlers||(this.eventHandlers={});this.eventHandlers[t]=i};QyScene.prototype.selfListen=function(e,t){this.objListen(this,e,t)};QyScene.prototype.dispatchEvent=function(e){!this.eventHandlers||"string"==typeof e&&!this.eventHandlers[e]||"object"==typeof e&&!this.eventHandlers[e.type]||("string"==typeof e?this.eventHandlers[e].call(this):"object"==typeof e&&this.eventHandlers[e.type].call(this,e))};