Cocos2d-JS 2017.1.16-代码阅读笔记

导演管理整个场景,场景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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值