Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cocos2d-js:定制加载界面大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
http://blog.csdn.net/jonahzheng/article/details/38348255

cocos2d进入游戏前都有一个默认的加载界面,如图,如果要自己定制这个加载界面,应该如何做呢


以下是main.js的代码

[javascript] view plain copy @L_262_2@ ?
  1. cc.game.onStart=function(){
  2. //1,
  3. //cc.view.adjustViewPort(true);
  4. //2.根据不同的环境设置不同的分辨率
  5. if(cc.sys.isMobilE)
  6. cc.view.setDesignResolutionSize(320,500,cc.ResolutionPolicy.FIXED_WIDTH);
  7. elsecc.view.setDesignResolutionSize(320,480,cc.ResolutionPolicy.SHOW_ALL)
  8. //cc.view.setDesignResolutionSize(800,450,cc.ResolutionPolicy.EXACT_FIT);
  9. cc.view.resizeWithBrowserSize(true);
  10. //3.预加载
  11. cc.LoaderScene.preload(g_resources,function(){
  12. //4.加载第一场景
  13. cc.director.runScene(newGameScene());
  14. },this);
  15. };
  16. cc.game.run();

其中cc.LoaderScene就是Loading界面的实现类,对应的文件就是CCLoaderScene.js,我们只需参这个文件自定义一个LoaderScene类就可以了。

类名叫MyLoading,代码如下

    varlogoData="data:image/jpeg;base64,/9.............";//图片的base64数据
  1. @H_440_31@myLoading=cc.Scene.extend({
  2. _interval:null,
  3. _length:0,
  4. _count:0,
  5. _label:null,
  6. _winSize:null,153); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> _className:"MyLoading",248)"> _processLayer:null,153); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> _processLayerLength:null,153); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> init:function(){
  7. varself=this;
  8. //logo
  9. varlogoWidth=160;
  10. varlogoHeight=200;
  11. //bg
  12. varbgLayer=self._bgLayer=cc.LayerColor.create(cc.color(32,32,255));
  13. bgLayer.setPosition(cc.visibleRect.bottomLeft);
  14. self.addChild(bgLayer,0);
  15. //imagemovetoCCSceneFile.js
  16. varfontSize=24,lblHeight=-logoHeight/2+100;
  17. if(cc._loaderImagE){
  18. //loadinglogo
  19. cc.loader.loadImg(logoData,{isCrossOrigin:false},function(err,img){
  20. logoWidth=img.width;
  21. logoHeight=img.height;
  22. self._initStage(img,cc.visibleRect.center);
  23. });
  24. fontSize=14;
  25. lblHeight=-logoHeight/2-10;
  26. //}
  27. //loadingpercent
  28. varlabel=self._label=cc.LabelTTF.create("Loading...0%","Arial",fontSizE);
  29. label.setPosition(cc.pAdd(cc.visibleRect.center,cc.p(0,lblHeight)));
  30. label.setColor(cc.color(180,180,180));
  31. bgLayer.addChild(this._label,10);
  32. //定义进度条层
  33. this._winSize=cc.director.getWinSize();
  34. varcenterPos=cc.p(this._winSize.width/2,this._winSize.height/2);
  35. self._processLayerLength=500;
  36. self._processLayer=cc.LayerColor.create(cc.color(255,100,128),1,30);
  37. self._processLayer.setPosition(cc.pAdd(centerPos,cc.p(-this._processLayerLength/2,-logoHeight/2-50)));
  38. self._bgLayer.addChild(this._processLayer);
  39. returntrue;
  40. _initStage:function(img,centerPos){
  41. varself=this;
  42. vartexture2d=self._texture2d=newcc.Texture2D();
  43. texture2d.initWitHelement(img);
  44. texture2d.handleLoadedTexture();
  45. varlogo=self._logo=cc.Sprite.create(texture2d);
  46. logo.setScale(cc.contentScaleFactor());
  47. logo.x=centerPos.x;
  48. logo.y=centerPos.y;
  49. self._bgLayer.addChild(logo,10);
  50. onEnter:function(){
  51. cc.Node.prototype.onEnter.call(self);
  52. self.schedule(self._startLoading,0.3);
  53. onExit:function(){
  54. cc.Node.prototype.onExit.call(this);
  55. vartmpStr="Loading...0%";
  56. this._label.set@R_197_10495@ng(tmpStr);
  57. /**
  58. *initwithresources
  59. *@param{Array}resources
  60. *@param{Function|@R_197_10495@ng}cb
  61. */
  62. initWithresources:function(resources,cb){
  63. if(typeofresources=="@R_197_10495@ng")resources=[resources];
  64. this.resources=resources||[];
  65. this.cb=cb;
  66. },153); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> _startLoading:function(){
  67. self.unschedule(self._startLoading);
  68. varres=self.resources;
  69. self._length=res.length;
  70. self._count=0;
  71. cc.loader.load(res,function(result,count){self._count=count;},function(){
  72. if(self.cb)
  73. self.cb();
  74. });
  75. self.schedule(self._updatePercent);
  76. _updatePercent:function(){
  77. varcount=self._count;
  78. varlength=self._length;
  79. varpercent=(count/length*100)|0;
  80. percent=Math.min(percent,100);
  81. self._label.set@R_197_10495@ng("Loading..."+percent+"%");
  82. //更新进度条的长度
  83. this._processLayer.changeWidth(this._processLayerLength*percent/100);
  84. if(count>=length)self.unschedule(self._updatePercent);
  85. }
  86. @H_440_31@myLoading.preload=function(resources,248)"> var_cc=cc;
  87. if(!_cc.myLoading){
  88. _cc.myLoading=new@H_112_32@myLoading();
  89. _cc.myLoading.init();
  90. _cc.myLoading.initWithresources(resources,cb);
  91. cc.director.runScene(_cc.myLoading);
  92. return_cc.myLoading;
  93. };

大佬总结

以上是大佬教程为你收集整理的cocos2d-js:定制加载界面全部内容,希望文章能够帮你解决cocos2d-js:定制加载界面所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:cocoscocos2ddjs加载定制界面
猜你在找的Cocos2d-x相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap