This project is read-only.
The AppDelegate class is the third and final step to your game bootstrap sequence. Here is where you extend the CCApplication object to setup your game specific environment.

    internal class AppDelegate : CCApplication
        public AppDelegate(Game game, GraphicsDeviceManager graphics)
            : base(game, graphics)
            s_pSharedApplication = this;
            DrawManager.InitializeDisplay(game, graphics, DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight);

The call to InitializeDisplay performs the screen orientation setup and does some screen setup that you may have already done in your Game() constructor:

        public static void InitializeDisplay(Game game, GraphicsDeviceManager graphics, DisplayOrientation supportedOrientations)
            m_GraphicsDeviceMgr = graphics;
            SetOrientation(supportedOrientations, false);

            graphics.IsFullScreen = true;

            graphics.IsFullScreen = true;

            game.IsMouseVisible = true;
            graphics.IsFullScreen = false;

Next, after the base application loads content, it calls ApplicationDidFinishLaunching:

        public override bool ApplicationDidFinishLaunching()
            CCDirector pDirector = null;
                DrawManager.SetDesignResolutionSize(800f, 480f, ResolutionPolicy.ShowAll);
                //initialize director
                pDirector = CCDirector.SharedDirector;

                //turn on display FPS
                pDirector.DisplayStats = false;

                // set FPS. the default value is 1.0/60 if you don't call this
                pDirector.AnimationInterval = 1.0 / 60;
            catch (Exception ex)
                CCLog.Log("ApplicationDidFinishLaunching(): Error " + ex.ToString());

The media player's state is very important to your application. If a user is playing background music and starts to play your game, you don't want to interrupt the background music. The SharedMedia object will keeps information about the current background music so that it can be restored when the game terminates.

This final step sets up the display scale and font scaling. This is all completed with a single call:

DrawManager.SetDesignResolutionSize(800f, 480f, ResolutionPolicy.ShowAll);

The ResolutionPolicy is very important because it determines what your game will do when the design resolution does not match the device resolution. If you pick the ShowAll option then your entire game display will appear.

    public enum ResolutionPolicy
        // The entire application is visible in the specified area without trying to preserve the original aspect ratio. 
        // Distortion can occur, and the application may appear stretched or compressed.
        // The entire application fills the specified area, without distortion but possibly with some cropping, 
        // while maintaining the original aspect ratio of the application.
        // The entire application is visible in the specified area without distortion while maintaining the original 
        // aspect ratio of the application. Borders can appear on two sides of the application.


There are two final methods to setup in the AppDelegate. These methods will manage how your application goes into the background on a mobile device and then how it returns to the foreground.

        public override void ApplicationDidEnterBackground()

        public override void ApplicationWillEnterForeground()

Note that you need to call the base CCApplication's methods in these two methods. The CCTextureCache needs to be properly managed and this is done in the CCApplication's implementation of the background and foreground methods.

Last edited Jan 12, 2013 at 7:24 AM by totallyevil, version 1


No comments yet.