0.
ccb实际上就是一个脚本文件,在cocosBuilder上的一些操作实际上就是改变了,ccb脚本文件
1.CCBI动画
cc.BuilderReader.setResourcePath(目录); 目录:含有 .ccbi 的所有文件,ccbi用到的图片资源以及,plist文件等
this.br=cc.BuilderReader.load(CCBI ,this); CCBI:具体的某个ccbi文件路径
this.addChild(this.br); 添加到layer上,this.br可以看出一个控件
this.br.animationManager.setCompletedAnimationCallback(this,this.callBack); 运行ccbi动画完成后的回调函数callBack
this._story_ani1.animationManager.runAnimationsForSequenceNamed("animation"); animation:ccbi动画名,运行ccbi动画
2.CCBI例子
cc.BuilderReader.setResourcePath(‘ccbi目录’);
var nodeB=cc.BuilderReader.load('path/xx.ccbi');
nodeB.setPosition(cc.p(200, 100));
nodeB.animationManager.runAnimationsForSequenceNamed("动画名");
nodeB.animationManager.setCompletedAnimationCallback(this, this._ccbiAft);//回调方法 返回一个node
this.addChild(nodeB, 3, 1212);
放资源时一般 ccbi 一个目录aa
png 或 plist 在 aa/ccbResources目录里
例子的分析
1.CocosBuilderTest
var CocosBuilderTestScene = TestScene.extend({ runThisTest:function(){ //设置加载资源路径、创建加载对象、注册加载HelloCocosBuilderLayer cc.BuilderReader.setResourcePath("res/"); var ccNodeLoaderLibrary = cc.NodeLoaderLibrary.newDefaultCCNodeLoaderLibrary(); ccNodeLoaderLibrary.registerCCNodeLoader("HelloCocosBuilderLayer", new HelloCocosBuilderLayerLoader()); //创建ccbi类对象、加载资源路径设置、加载资源 var ccbReader = new cc.BuilderReader(ccNodeLoaderLibrary); ccbReader.setCCBRootPath("res/"); var node = ccbReader.readNodeGraphFromFile("res/ccb/HelloCocosBuilder.ccbi", this); //node 相当于普通控件 if(node != null) { this.addChild(node); } //跳转 cc.Director.getInstance().replaceScene(this); } });
var HelloCocosBuilderLayer = cc.Layer.extend({ _burstSprite:null, _testTitleLabelTTF:null, _customPropertyInt:0, _customPropertyFloat:0, _customPropertyBoolean:false, _customPropertyString:"", //跳转到其他 ccbi界面 openTest:function(ccbFileName, nodeName,nodeLoader){ var ccNodeLoaderLibrary = cc.NodeLoaderLibrary.newDefaultCCNodeLoaderLibrary(); ccNodeLoaderLibrary.registerCCNodeLoader("TestHeaderLayer", new TestHeaderLayerLoader()); if(nodeName != null && nodeLoader != null) { ccNodeLoaderLibrary.registerCCNodeLoader(nodeName, nodeLoader); } /* Create an autorelease CCBReader. */ var ccbReader = new cc.BuilderReader(ccNodeLoaderLibrary); ccbReader.setCCBRootPath("res/"); var node = ccbReader.readNodeGraphFromFile(ccbFileName, this); this._testTitleLabelTTF.setString(ccbFileName); var scene = cc.Scene.create(); if(node != null) scene.addChild(node); cc.Director.getInstance().pushScene(cc.TransitionFade.create(0.5, scene, cc.black())); }, //接受Menu对象 onResolveCCBCCMenuItemSelector:function(target,selectorName){ return null; }, //接受Button对象 onResolveCCBCCControlSelector:function(target,selectorName){ if(this == target && "onMenuTestClicked" == selectorName){ return this.onMenuTestClicked; } if(this == target && "onSpriteTestClicked" == selectorName){ return this.onSpriteTestClicked; } if(this == target && "onButtonTestClicked" == selectorName){ return this.onButtonTestClicked; } if(this == target && "onAnimationsTestClicked" == selectorName){ return this.onAnimationsTestClicked; } if(this == target && "onParticleSystemTestClicked" == selectorName){ return this.onParticleSystemTestClicked; } if(this == target && "onScrollViewTestClicked" == selectorName){ return this.onScrollViewTestClicked; } if(this == target && "onTimelineCallbackSoundClicked" == selectorName){ return this.onTimelineCallbackSoundClicked; } return null; }, //接受_burstSprite、LabelTTF、LabelBM等对象 onAssignCCBMemberVariable:function(target,memberVariableName,node){ if(target == this && memberVariableName == "mBurstSprite"){ if(node instanceof cc.Sprite){ this._burstSprite = node; } return true; } if(target == this && memberVariableName == "mTestTitleLabelTTF"){ if(node instanceof cc.LabelTTF){ this._testTitleLabelTTF = node; } return true; } return false; }, onAssignCCBCustomProperty:function(target, memberVariableName,ccbValue){ var bRet = false; if (target == this) { if (memberVariableName == "mCustomPropertyInt") { this._customPropertyInt = ccbValue; cc.log("CustomPropertyInt = " +this._customPropertyInt); bRet = true; } else if ( memberVariableName == "mCustomPropertyFloat") { this._customPropertyFloat = ccbValue; cc.log("CustomPropertyFloat = " + this._customPropertyFloat); bRet = true; } else if ( memberVariableName == "mCustomPropertyBoolean" ) { this._customPropertyBoolean = ccbValue; cc.log("CustomPropertyBoolean = " + this._customPropertyBoolean); bRet = true; } else if ( memberVariableName == "mCustomPropertyString" ) { this._customPropertyString = ccbValue; cc.log("CustomPropertyString = " + this._customPropertyString); bRet = true; } } return bRet; }, onNodeLoaded:function(node,nodeLoader){ var ccRotateBy = cc.RotateBy.create(20.0, 360); var ccRepeatForever = cc.RepeatForever.create(ccRotateBy); this._burstSprite.runAction(ccRepeatForever); }, //各个方法的回调 onMenuTestClicked:function(sender,controlEvent){ this.openTest("res/ccb/ccb/TestMenus.ccbi", "TestMenusLayer", new MenuTestLayerLoader()); }, onSpriteTestClicked:function(sender,controlEvent){ this.openTest("res/ccb/ccb/TestSprites.ccbi", "TestSpritesLayer", new SpriteTestLayerLoader()); }, onButtonTestClicked:function(sender,controlEvent){ this.openTest("res/ccb/ccb/TestButtons.ccbi", "TestButtonsLayer", new ButtonTestLayerLoader()); }, onAnimationsTestClicked:function(sender,controlEvent){ var actionManager; var ccNodeLoaderLibrary = cc.NodeLoaderLibrary.newDefaultCCNodeLoaderLibrary(); ccNodeLoaderLibrary.registerCCNodeLoader("TestHeaderLayer", new TestHeaderLayerLoader()); ccNodeLoaderLibrary.registerCCNodeLoader("TestAnimationsLayer", new AnimationsTestLayerLoader()); var ccbReader = new cc.BuilderReader(ccNodeLoaderLibrary); ccbReader.setCCBRootPath("res/"); var animationsTest = ccbReader.readNodeGraphFromFile("res/ccb/ccb/TestAnimations.ccbi", this, actionManager); //多了一个动画管理 actionManager = ccbReader.getAnimationManager(); animationsTest.setAnimationManager(actionManager); this._testTitleLabelTTF.setString("TestAnimations.ccbi"); var scene = cc.Scene.create(); if(animationsTest != null) { scene.addChild(animationsTest); } //跳转界面 var transitionColor = cc.c3b(0,0,0); cc.Director.getInstance().pushScene(cc.TransitionFade.create(0.5, scene, transitionColor)); //this.openTest("ccb/ccb/TestAnimations.ccbi", "TestAnimationsLayer", new AnimationsTestLayerLoader()); }, onParticleSystemTestClicked:function(sender,controlEvent){ this.openTest("res/ccb/ccb/TestParticleSystems.ccbi", "TestParticleSystemsLayer", new ParticleSystemTestLayerLoader()); }, onScrollViewTestClicked:function(sender,controlEvent){ this.openTest("res/ccb/ccb/TestScrollViews.ccbi", "TestScrollViewsLayer", new ScrollViewTestLayerLoader()); }, onTimelineCallbackSoundClicked:function(sender,controlEvent){ this.openTest("res/ccb/ccb/TestTimelineCallback.ccbi", "TimelineCallbackTestLayer", new TimelineCallbackTestLayerLoader()); } }); HelloCocosBuilderLayer.create = function(){ var retLayer = new HelloCocosBuilderLayer(); if(retLayer && retLayer.init()){ return retLayer; } return null; }; var HelloCocosBuilderLayerLoader = cc.LayerLoader.extend({ _createCCNode:function(parent,ccbReader){ return HelloCocosBuilderLayer.create(); } });