一般游戏都包括几个流程,加载界面,开始界面,选关界面,主界面,暂停界面等等;这节我将这些流程都串联起来;


代码下载:http://www.kuaipan.cn/file/id_25348935635745200.htm?source=1


loading界面;


LoadingLayer.ccbx


  1. <?xmlversion="1.0"encoding="UTF-8"?>

  2. <Document

  3. jsControlled="true"

  4. jsController=""

  5. resolution="default"

  6. >

  7. <Resolutions>

  8. <ResolutioncenteredOrigin="false"ext="iphone"height="1280"width="720"name="default"scale="1"/>

  9. <ResolutioncenteredOrigin="false"ext="iphone"height="720"width="1280"name="default1"scale="1"/>

  10. </Resolutions>

  11. <Animations>

  12. <AnimationautoPlay="true"

  13. id="0"

  14. name="Default Timeline"

  15. length="10"

  16. chainedId="0"

  17. offset="0.0"

  18. position="0.0"

  19. resolution="30"

  20. scale="128">

  21. <CallbackChannel>

  22. </CallbackChannel>

  23. <SoundChannel>

  24. </SoundChannel>

  25. </Animation>

  26. </Animations>

  27. <Layer

  28. positionX="0"positionY="0"

  29. width="100"height="100"sizeType="Percent"

  30. anchorPointX="0.5"anchorPointY="0.5"ignoreAnchorPoint="true"

  31. scaleX="1"scaleY="1"

  32. touchEnabled="true"positionType="LeftBottom"target="Owner">

  33. <LayerColorpositionType="LeftBottom"width="720"height="1280"positionX="0"positionY="0"anchorPointX="0"

  34. anchorPointY="0"color="#ffff40b8"target="Doc"/>

  35. <SpritepositionType="LeftBottom"width="245.0"height="72.0"positionX="381.0"positionY="661.0"anchorPointX="0.5"

  36. anchorPointY="0.5"src="Resources/snow_packer.plist/sa_loading_0001.png"

  37. target="Owner"/>

  38. </Layer>

  39. </Document>



开始界面;


StartLayer.ccbx


  1. <?xmlversion="1.0"encoding="UTF-8"?>

  2. <Document

  3. jsControlled="true"

  4. jsController="StartLayer"

  5. resolution="default"

  6. >

  7. <Resolutions>

  8. <ResolutioncenteredOrigin="false"ext="iphone"height="1280"width="720"name="default"scale="1"/>

  9. <ResolutioncenteredOrigin="false"ext="iphone"height="720"width="1280"name="default1"scale="1"/>

  10. </Resolutions>

  11. <Animations>

  12. <AnimationautoPlay="true"

  13. id="0"

  14. name="Default Timeline"

  15. length="10"

  16. chainedId="0"

  17. offset="0.0"

  18. position="0.0"

  19. resolution="30"

  20. scale="128">

  21. <CallbackChannel>

  22. </CallbackChannel>

  23. <SoundChannel>

  24. </SoundChannel>

  25. </Animation>

  26. </Animations>

  27. <Layer

  28. positionX="0"positionY="0"

  29. width="100"height="100"sizeType="Percent"

  30. anchorPointX="0.5"anchorPointY="0.5"ignoreAnchorPoint="true"

  31. scaleX="1"scaleY="1"

  32. touchEnabled="true"positionType="LeftBottom"visible="true">

  33. <LayerColorpositionType="LeftBottom"width="720"height="1280"positionX="0"positionY="0"anchorPointX="0"

  34. anchorPointY="0"color="#ff10ff9e"/>

  35. <MenupositionType="LeftBottom"width="40"height="40"positionX="354.0"positionY="712.0"anchorPointX="0.5"

  36. anchorPointY="0.5">

  37. <MenuItempositionType="LeftBottom"width="203"height="129"positionX="0"positionY="0"anchorPointX="0.5"

  38. anchorPointY="0.5"onClick="onPlayClicked"normalImage="Resources/snow_packer.plist/m_play.png"

  39. target="Doc"selectedImage="Resources/snow_packer.plist/m_play.png"/>

  40. </Menu>

  41. </Layer>

  42. </Document>


StartLayer.js



[Javascript]view plaincopy
  1. //

  2. // CleanerScoreScene class

  3. //

  4. var StartLayer = function () {  

  5.    cc.log("StartLayer")  

  6. this.LoadingLayer = this.LoadingLayer || {};  

  7. this.passTime = 0;  

  8. this.goStart = false;  

  9. };  

  10. StartLayer.prototype.OnDidLoadFromCCB= function () {  

  11. //    this.rootNode.OnUpdate= function (dt)

  12. //    {

  13. //        this.controller.onUpdate();

  14. //    };

  15. //    this.rootNode.schedule(this.rootNode.onUpdate);

  16. if (sys.platform == 'browser') {  

  17. this.onEnter();  

  18.    }  

  19. else {  

  20. this.rootNode.OnEnter= function () {  

  21. this.controller.onEnter();  

  22.        };  

  23.    }  

  24. this.rootNode.OnExit= function () {  

  25. this.controller.onExit();  

  26.    };  

  27. this.rootNode.schedule(function (dt) {  

  28. this.controller.onUpdate(dt);  

  29.    });  

  30. };  

  31. StartLayer.prototype.OnEnter= function () {  

  32. this.LoadingLayer = cc.BuilderReader.loadAsNodeFrom("", "LoadingLayer", this);  

  33. this.LoadingLayer.setPosition(cc.p(0, 0));  

  34. this.LoadingLayer.setZOrder(200);  

  35. this.rootNode.addChild(this.LoadingLayer);  

  36. //  cc.Director.getInstance().pause();

  37. /*this.LoadingLayer.scheduleOnce(this.removeLoading, 1);*/

  38. this.goStart = true;  

  39. this.startTime = this.passTime;  

  40. }  

  41. StartLayer.prototype.removeLoading = function () {  

  42. // if (this.LoadingLayer) {

  43.    cc.log("removeLoading");  

  44. // cc.Director.getInstance().resume();

  45. this.LoadingLayer.removeFromParent();  

  46. }  

  47. StartLayer.prototype.OnUpdate= function (dt) {  

  48. this.passTime += dt;  

  49. if (this.passTime - this.startTime > 3 && this.goStart) {  

  50. this.removeLoading();  

  51. this.goStart = false;  

  52.    }  

  53. }  

  54. StartLayer.prototype.OnPlayClicked= function () {  

  55.    cc.BuilderReader.runScene("", "GameSelectLayer");  

  56. }  

  57. StartLayer.prototype.OnExit= function () {  

  58. }  

继续请点击:http://makeapp.blog.51cto.com/8596155/1361300