CCGameView
CCGameView
Cocos2DCCGameView is an embeddable view that hosts a cocos2d-mono game. This is a partial class with platform-specific implementations.
Inheritance: System.Object
Implements: System.IDisposable
Constructors
CCGameView(Context)
CCGameView(Context)(Android.Content.Context context)Creates a new CCGameView for embedding in an Android Activity. The view will be available through the AndroidView property after initialization.
Parameters:
context (Android.Content.Context) - The Android context (typically the Activity).Example
CCGameView(Context, CCGameView)
CCGameView(Context, CCGameView)(Android.Content.Context context, Cocos2D.CCGameView primaryView)Creates a secondary CCGameView that will share another view's game loop. Use AttachSecondaryView on the primary view to connect them.
Parameters:
context (Android.Content.Context) - The Android context.primaryView (Cocos2D.CCGameView) - The primary view that will drive the game loop.Example
CCGameView(Context, int, int)
CCGameView(Context, int, int)(Android.Content.Context context, System.Int32 width, System.Int32 height)Creates a new CCGameView with specified dimensions.
Parameters:
context (Android.Content.Context) - The Android context (typically the Activity).width (System.Int32) - Initial width in pixels.height (System.Int32) - Initial height in pixels.Example
CCGameView(CGRect)
CCGameView(CGRect)(CoreGraphics.CGRect frame)Parameters:
frame (CoreGraphics.CGRect)CCGameView(NSCoder)
CCGameView(NSCoder)(Foundation.NSCoder coder)Parameters:
coder (Foundation.NSCoder)CCGameView(Game, GraphicsDeviceManager)
CCGameView(Game, GraphicsDeviceManager)(Microsoft.Xna.Framework.Game game, Microsoft.Xna.Framework.GraphicsDeviceManager graphics)Creates a new CCGameView with an existing MonoGame Game instance. Use this if you already have a Game and want to integrate CCGameView.
Parameters:
game (Microsoft.Xna.Framework.Game) - The MonoGame Game instance.graphics (Microsoft.Xna.Framework.GraphicsDeviceManager) - The GraphicsDeviceManager from the game.Example
Fields
Indicates whether platform-specific initialization is complete. Set by platform-specific implementations after initialization.
Properties
Gets the accelerometer for this view.
Gets the action manager.
Gets the Android View that can be added to a layout. This is the MonoGame surface view.
Gets the content manager for loading assets.
Gets or sets the root directory for content loading. Must be set before calling StartGame(). Default is "Content".
Gets or sets the design resolution size. This is the logical resolution that your game is designed for.
Gets the director that manages scenes.
Gets the internal MonoGame Game instance.
Gets the graphics device used for rendering.
Gets whether this view is a secondary view attached to another view's game loop.
Gets or sets whether the view is paused. When paused, the game loop will not update or render.
Gets or sets the resolution policy that determines how the design resolution is mapped to the actual view size.
Gets the scene running in this view. If a view-specific scene is set, returns that; otherwise returns the shared director's scene.
Gets the scheduler that manages scheduled callbacks.
Gets or sets whether split-screen mode is enabled. When enabled, the view renders two scenes side by side.
Gets the secondary scene in split-screen mode.
Gets or sets whether touch input is enabled.
Gets the actual size of the view in pixels.
Gets or sets the custom viewport ratio. Setting this will automatically change the resolution policy to Custom.
Methods
AddIncomingNewTouch(int, ref CCPoint)
AddIncomingNewTouch(int, ref CCPoint)(System.Int32 touchId, Cocos2D.CCPoint position)Adds a new touch to the incoming touch queue.
Parameters:
touchId (System.Int32)position (Cocos2D.CCPoint)Example
AttachSecondaryView(CCGameView)
AttachSecondaryView(CCGameView)(Cocos2D.CCGameView secondaryView)Attaches a secondary view to share this view's game loop. The secondary view will be updated and drawn when this view is updated/drawn. Use this for side-by-side multi-view layouts where views share the same graphics device.
Parameters:
secondaryView (Cocos2D.CCGameView) - The view to attach as a secondary view.Example
ClearTouches()
ClearTouches()()Clears all tracked touches. Call this when the view is paused or loses focus.
Example
DetachSecondaryView(CCGameView)
DetachSecondaryView(CCGameView)(Cocos2D.CCGameView secondaryView)Detaches a secondary view from this view's game loop.
Parameters:
secondaryView (Cocos2D.CCGameView) - The view to detach.Example
Dispose()
Dispose()()Disposes the view and releases all resources.
Example
Dispose(bool)
Dispose(bool)(System.Boolean disposing)Disposes the view and releases resources.
Parameters:
disposing (System.Boolean) - True if called from Dispose(), false if called from finalizer.Example
DrawSecondaryViews(GameTime)
DrawSecondaryViews(GameTime)(Microsoft.Xna.Framework.GameTime gameTime)Draws all attached secondary views. Called by platform-specific draw methods.
Parameters:
gameTime (Microsoft.Xna.Framework.GameTime)Example
DrawView(GameTime)
DrawView(GameTime)(Microsoft.Xna.Framework.GameTime gameTime)Call this from your MonoGame Game.Draw() method if using Game-based constructor.
Parameters:
gameTime (Microsoft.Xna.Framework.GameTime) - The game time from MonoGame.Example
~CCGameView()
~CCGameView()()Finalizer.
Example
LayoutSubviews()
LayoutSubviews()()Example
ProcessTouchInput()
ProcessTouchInput()()Process touch input from MonoGame's TouchPanel. Call this if you need to manually process touch events.
Example
ReplaceScene(CCScene)
ReplaceScene(CCScene)(Cocos2D.CCScene scene)Replaces the current scene running in this view. Only works if the view is running its own scene (useViewScene was true).
Parameters:
scene (Cocos2D.CCScene) - The new scene to run.Example
ReplaceSplitScreenScene(CCScene)
ReplaceSplitScreenScene(CCScene)(Cocos2D.CCScene scene)Replaces the split-screen scene.
Parameters:
scene (Cocos2D.CCScene) - The new scene to render in the right half.Example
Run()
Run()()Runs the internal game loop. Call this after setting the content view. This method blocks until the game exits.
Example
RunWithScene(CCScene, bool)
RunWithScene(CCScene, bool)(Cocos2D.CCScene scene, System.Boolean useViewScene)Starts the game and runs the specified scene. When useViewScene is true, the scene runs independently in this view, allowing multiple views to show different scenes.
Parameters:
scene (Cocos2D.CCScene) - The scene to run.useViewScene (System.Boolean) - If true, the scene runs only in this view. Default is false for backward compatibility.Example
SetSplitScreenScene(CCScene)
SetSplitScreenScene(CCScene)(Cocos2D.CCScene scene)Sets the secondary scene for split-screen mode. The primary scene renders on the left, the split-screen scene renders on the right.
Parameters:
scene (Cocos2D.CCScene) - The scene to render in the right half of the view.Example
StartAsSecondaryView()
StartAsSecondaryView()()Initializes this view as a secondary view attached to a primary view. The secondary view will share the primary view's game loop and graphics device. Call this instead of StartGame() and Run() for secondary views.
Example
StartGame()
StartGame()()Starts the game loop.
Example
TouchesBegan(NSSet, UIEvent)
TouchesBegan(NSSet, UIEvent)(Foundation.NSSet touches, UIKit.UIEvent evt)Parameters:
touches (Foundation.NSSet)evt (UIKit.UIEvent)Example
TouchesCancelled(NSSet, UIEvent)
TouchesCancelled(NSSet, UIEvent)(Foundation.NSSet touches, UIKit.UIEvent evt)Parameters:
touches (Foundation.NSSet)evt (UIKit.UIEvent)Example
TouchesEnded(NSSet, UIEvent)
TouchesEnded(NSSet, UIEvent)(Foundation.NSSet touches, UIKit.UIEvent evt)Parameters:
touches (Foundation.NSSet)evt (UIKit.UIEvent)Example
TouchesMoved(NSSet, UIEvent)
TouchesMoved(NSSet, UIEvent)(Foundation.NSSet touches, UIKit.UIEvent evt)Parameters:
touches (Foundation.NSSet)evt (UIKit.UIEvent)Example
UpdateIncomingMoveTouch(int, ref CCPoint)
UpdateIncomingMoveTouch(int, ref CCPoint)(System.Int32 touchId, Cocos2D.CCPoint position)Updates an existing touch with move information.
Parameters:
touchId (System.Int32)position (Cocos2D.CCPoint)Example
UpdateIncomingReleaseTouch(int)
UpdateIncomingReleaseTouch(int)(System.Int32 touchId)Updates an existing touch to indicate it has been released.
Parameters:
touchId (System.Int32)Example
UpdateSecondaryViews(GameTime)
UpdateSecondaryViews(GameTime)(Microsoft.Xna.Framework.GameTime gameTime)Updates all attached secondary views. Called by platform-specific update methods.
Parameters:
gameTime (Microsoft.Xna.Framework.GameTime)Example
UpdateView(GameTime)
UpdateView(GameTime)(Microsoft.Xna.Framework.GameTime gameTime)Call this from your MonoGame Game.Update() method if using Game-based constructor.
Parameters:
gameTime (Microsoft.Xna.Framework.GameTime) - The game time from MonoGame.Example
UpdateViewSize(int, int)
UpdateViewSize(int, int)(System.Int32 width, System.Int32 height)Updates the view size. Call this when the window is resized.
Parameters:
width (System.Int32) - New width in pixels.height (System.Int32) - New height in pixels.Example
Events
Event raised when the view is created and ready for use. When you subscribe to this event, the game will be loaded.