Cocos2d-JS 2017.1.16-代码阅读笔记

来源:互联网 发布:波士顿矩阵ppt模板 编辑:程序博客网 时间:2024/05/02 03:06

导演管理整个场景,场景Scene.永远有且只有一个存在。

层是添加到Scene上的。

导演管理动画的播放stopAnimation。如果通过变量invalid控制。

call:继承的时候改变this的指向,call里面的对象变成this。

mainLoop: function () {    if (this._purgeDirectorInNextLoop) {        this._purgeDirectorInNextLoop = false;        this.purgeDirector();    }    else if (!this.invalid) {        this.drawScene();    }},
当导演管理栈长度为0时,调用:::
end: function () {    this._purgeDirectorInNextLoop = true;},
_purgeDirectorInNextLoop == true时,净化导演,清除定时器
this.getScheduler().unsheduleAll();
if ( cc.eventMananger )
cc.eventManager.setEnabled( false );
if ( this._runningScene )
this._runningScene.onExitTransitionDidStart();
this._runningScene.onExit();
this._runningScene.cleanUp();
this._runningScene = null;
this._nextScene = null;
this._scenesStack.length = 0;
this.purgeCachedData();
purgeCachedData: function () {    cc.animationCache._clear();    cc.spriteFrameCache._clear();    cc.textureCache._clear();},
/** * Stops animation */stopAnimation: function () {    this.invalid = true;},
在drawScene() 里面:==》
cc.renderer = cc.rendererWebGL;
this.setNextScene(),绘制下一个Scene的操作。
cc.eventManager.dispatchEvent(this._eventAfterDraw);//派发时间
this._eventAfterDraw = new cc.EventCustom(cc.Director.EVENT_AFTER_DRAW);this._eventAfterDraw.setUserData(this);
if (this._afterVisitScene)    this._afterVisitScene();
函数放到IF条件变量里面。必须得去掉括号!!!
cc.Node.prototype.onExitTransitionDidStart.call(this);
// 加载资源,并进入游戏  在resource.js 中添加的地图中的资源组cc.LoaderScene.preload(g_gamePlay_resources, function () {    GameManager.loadLevelData(GameManager.getLevel());    cc.director.runScene(new GamePlayScene());}, this);
cc.LoaderScene.preload( g_gamePlay_resources, function () {
GameManager.loadLevelData( GameManager.getLevel() );
cc.director.runScene( new GamePlayScene());
}, this};
瓦片地图资源::
var node = new cc.TMXTiledMap("res/ChooseLevel/Map/TiledMap.tmx");
var objectGroup = node.getObjectGroup("point"); //获得瓦片地图中的格子地图信息
var objs = objectGroup.getObjects();
//在场景的构造函数添加播放音乐,达到人未到声先到的效果
cc.audioEngine.playMusic("res/Sound/GamePlay/BGMusic01.mp3", true);
//停止音乐cc.audioEngine.stopMusic();
事件:: 通过事件来对其他层进行处理一些操作
在Menu.js中// 触摸事件结束时响应
// [事件抛出]隐藏菜单层var event = new cc.EventCustom(jf.EventName.GP_REMOVE_MENU_LAYER);cc.eventManager.dispatchEvent(event); //事件管理层派发事件
在GamePlay.js中监听事件::移除菜单层var onRemoveMenuLayerListener = cc.EventListener.create({    event       : cc.EventListener.CUSTOM,    target      : this,    eventName   : jf.EventName.GP_REMOVE_MENU_LAYER ,    callback    : this.onRemoveMenuLayer});cc.eventManager.addListener(onRemoveMenuLayerListener, this);
ScrollView的创建::
var node = new ccui.ScrollView();this.addChild( node );this.scorllView = node;node.setDirection( ccui.ScrollView.DIR_HORIZONTAL );// 水平方向node.setTouchEnabled( true ); // 吞噬触摸node.setContentSize( cc.winSize ); // 设置容器大小
var nextPos = 0;var imageView = null;for ( var i = 0; i< 14; i++ ) {    imageView = new ccui.ImageView( "res/ChooseLevel/Map/stage_map_" + i + ".png" );    node.addChild( imageView );    imageView.setAnchorPoint( cc.p( 0, 0.5 ) );    imageView.setPosition( nextPosX, cc.winSize.height );    nextPosX += imageView.width;}node.setInnerContainerSize( cc.size(nextPosX, cc.winSize.height ) ); //容器的大小 width, height

0 0
原创粉丝点击