/** * Run main loop of director */ mainLoop: function () { if (this._purgeDirectorInNextLoop) { this._purgeDirectorInNextLoop = false; this.purgeDirector(); } elseif (!this.invalid) { this.drawScene(); } },
//tick before glClear: issue #533 if (!this._paused) { this._scheduler.update(this._deltaTime); cc.eventManager.dispatchEvent(this._eventAfterUpdate); }
//首先执行调度器中的任务,然后触发cc.director.EVENT_AFTER_UPDATE事件,检查交互事件,有的话就分发处理 /* to avoid flickr, nextScene MUST be here: after tick and before draw. XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */ if (this._nextScene) { this.setNextScene(); } //如果有场景切换,便切换 //渲染当前scene // draw the scene if (this._runningScene) { if (renderer.childrenOrderDirty) { cc.renderer.clearRenderCommands(); cc.renderer.assignedZ = 0; this._runningScene._renderCmd._curLevel = 0; //level start from 0; this._runningScene.visit(); renderer.resetFlag(); } elseif (renderer.transformDirty()) { renderer.transform(); } }
renderer.clear();
// draw the notifications node if (this._notificationNode) this._notificationNode.visit(); //遍历节点,更新节点的空间转换矩阵,发送指令给渲染器 cc.eventManager.dispatchEvent(this._eventAfterVisit); cc.g_NumberOfDraws = 0;