CocosSharp.CCApplication Class
Initializes game and handles input events.

See Also: CCApplication Members

Syntax

public class CCApplication : Microsoft.Xna.Framework.DrawableGameComponent

Remarks

Manages the running state, scheduling, event handling and rendering of a game.

A CCApplication maintains a list of CocosSharp.CCWindow objects (due to current MonoGame limitations, currently only supports a single window). During each iteration of the game run-loop, the application invokes the CCApplication.Update method where it processes input-events, passing the relevant events to the corresponding windows.

Additionally, in-game time-dependent events, such as running actions, are also updated. Subsequently, a Draw call is received and each of the windows are asked to redraw themselves.

c# Example

// Default case
// 
// Single director/viewport
// Layer's camera uses default visible bounds given by window design resolution
// Default viewport takes up entire window screen

public class AppDelegate : CCApplicationDelegate
{
    public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
    {
        mainWindow.SetDesignResolutionSize(960, 640, CCSceneResolutionPolicy.ShowAll);

        CCScene scene = new CCScene(mainWindow);
        CCLayer layer = new MyLayer();

        scene.AddChild(layer);
        sharedWindow.RunWithScene(scene);
    }
}

//  Custom camera
// 
// As above, with the exception that layer uses custom camera

public class AppDelegate : CCApplicationDelegate
{
    public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
    {
        mainWindow.SetDesignResolutionSize(960, 640, CCSceneResolutionPolicy.ShowAll);

        var scene = new CCScene(mainWindow);
        var layer = new MyLayer();

        var cameraVisibleBounds = new CCSize(1000, 500);
        var cameraTarget = new CCPoint3(0, 0, 3);
        var cameraPosition = new CCPoint3(0, 0, 100);
        var camera = new CCCamera(cameraVisibleBounds, cameraPosition, cameraTarget);
        
        layer.Camera = Camera;

        scene.AddChild(layer);
        sharedWindow.RunWithScene(scene);
    }
}

// Custom viewport
// 
// As with the default, with the exception that the scene uses a custom viewport

public class AppDelegate : CCApplicationDelegate
{
    public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
    {
        mainWindow.SetDesignResolutionSize(960, 640, CCSceneResolutionPolicy.ShowAll);
        
        // Specify the ratio of the screen to occupy
        // Note: top-left corner represents origin in screen space
        CCViewport topLeftViewport = new CCViewport(new CCRect(0.0f, 0.0f, 0.5f, 0.5f));

        var scene = new CCScene(mainWindow, topLeftViewport);
        
        // Make sure we set custom policy, or else we to default to policy set by window
        // i.e. CCSceneResolutionPolicy.ShowAll implies that entire screen is used
        scene.SceneResolutionPolicy = CCSceneResolutionPolicy.Custom;

        var layer = new MyLayer();

        scene.AddChild(layer);
        sharedWindow.RunWithScene(scene);
    }
}

// Multiple running scenes/viewport
// 
// Create multiple scene directors to have multiple running scenes

public class AppDelegate : CCApplicationDelegate
{
    public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
    {
        mainWindow.SetDesignResolutionSize(960, 640, CCSceneResolutionPolicy.ShowAll);

        var topLeftViewport = new CCViewport(new CCRect(0.0f, 0.0f, 0.5f, 0.5f));
        var topRightViewport = new CCViewport(new CCRect(0.5f, 0.0f, 0.5f, 0.5f));

        var sceneDirector1 = new CCDirector();
        var sceneDirector2 = new CCDirector();

        var scene1 = new CCScene(mainWindow, topLeftViewport, sceneDirector1) {
            SceneResolutionPolicy = CCSceneResolutionPolicy.Custom
	};

        CCScene scene2 = new CCScene(mainWindow, topRightViewport, sceneDirector2) {
            SceneResolutionPolicy = CCSceneResolutionPolicy.Custom 
        };

        var layer1 = new MyLayer();
        var layer2 = new MyLayer2();

        scene1.AddChild(layer1);
        scene2.AddChild(layer2);

        sceneDirector1.RunWithScene(scene1);
        sceneDirector2.RunWithScene(scene2);
    }
}
	

Requirements

Namespace: CocosSharp
Assembly: CocosSharp (in CocosSharp.dll)