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