AppControl.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2008-2010 Ricardo Quesada
  4. Copyright (c) 2011 Zynga Inc.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. /**
  23. * Controller of Game Application
  24. * @class
  25. * @extends cc.Class
  26. */
  27. cc.AppController = cc.Class.extend(/** @lends cc.AppController# */{
  28. /**
  29. * did something when Finish Launching
  30. * @return {Boolean}
  31. */
  32. didFinishLaunchingWithOptions:function () {
  33. // Override point for customization after application launch.
  34. //var app = new cc.AppDelegate();
  35. cc.Application.getInstance().run();
  36. return true;
  37. },
  38. /**
  39. * <p>
  40. * Sent when the application is about to move from active to inactive state. <br/>
  41. * This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) <br/>
  42. * or when the user quits the application and it begins the transition to the background state. <br/>
  43. * Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. <br/>
  44. * Games should use this method to pause the game.
  45. * </p>
  46. */
  47. applicationWillResignActive:function () {
  48. cc.Director.getInstance().pause();
  49. },
  50. /**
  51. * <p>
  52. * Restart any tasks that were paused (or not yet started) while the application was inactive. <br/>
  53. * If the application was previously in the background, optionally refresh the user interface.
  54. * </p>
  55. */
  56. applicationDidBecomeActive:function () {
  57. cc.Director.getInstance().resume();
  58. },
  59. /**
  60. * <p>
  61. * Use this method to release shared resources, save user data, invalidate timers, and store enough application state information <br/>
  62. * to restore your application to its current state in case it is terminated later.<br/>
  63. * If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
  64. * </p>
  65. */
  66. applicationDidEnterBackground:function () {
  67. cc.Application.getInstance().applicationDidEnterBackground();
  68. },
  69. /**
  70. * <p>
  71. * Called as part of transition from the background to the inactive state: <br/>
  72. * here you can undo many of the changes made on entering the background.
  73. * </p>
  74. */
  75. applicationWillEnterForeground:function () {
  76. cc.Application.getInstance().applicationWillEnterForeground();
  77. },
  78. /**
  79. * Called when the application is about to terminate. See also applicationDidEnterBackground.
  80. */
  81. applicationWillTerminate:function () {
  82. }
  83. });
  84. /**
  85. * Return Controller of Game Application
  86. * @return {cc.AppController}
  87. */
  88. cc.AppController.shareAppController = function () {
  89. if (cc.sharedAppController == null) {
  90. cc.sharedAppController = new cc.AppController();
  91. }
  92. if(!cc.sharedAppController)
  93. throw "Application initialize failure";
  94. return cc.sharedAppController;
  95. };
  96. /**
  97. * cocos2d application instance
  98. * @type cc.AppController
  99. */
  100. cc.sharedAppController = null;