Using 2D Animation with CocosSharp In Xamarin Forms

CocosSharp is an easy to use library for simple games using C# and F#. It is a .NET port of the popular Cocos2D engine, derived from the Cocos2D-X engine via Cocos2D-XNA.
The CocosSharp 2D game engine provides technology for making cross-platform games. For a full list of supported platforms see the CocosSharp wiki on GitHub.
The core of CocosSharp is provided by the MonoGame framework, which is itself a cross-platform, hardware accelerated API providing graphics, audio, game state management, input, and a content pipeline for importing assets. CocosSharp is an efficient abstraction layer well suited for 2D games.

Using CocosSharp in xamarin forms.
CocosSharp can be used to add precise shape, image, and text rendering to an application for advanced visualisation.
CocosSharp is a runtime-efficient library which includes the following features:

1. Image rendering using the CCSprite class
2. Shape rendering using the CCDrawNode class
3. Every-frame logic using the CCNode.Schedule method
4. Content management (loading and unloading of resources such as .png files) using
the CCTextureCache class
5. Animations using the CCAction class
CocosSharp’s primary focus is to simplify the creation of cross-platform 2D games; however, it can also be a great addition to Xamarin Form applications. Since games typically require efficient rendering and precise control over visuals, CocosSharp can be used to add powerful visualisation and effects to non-game applications.

Xamarin.Forms is built upon native, platform-specific UI systems. For example, Buttons appear differently on iOS and Android, and may even differ by operating system version. By contrast, CocosSharp does not use any platform-specific visual objects, so all visual objects appear identical on all platforms. Of course, resolution and aspect ratio differ between devices, and this can impact how CocosSharp renders its visuals.

Adding the CocosSharp Nuget packages.
The CocosSharp Nuget package contains all of the objects needed to create CocosSharp objects. The CocosSharp.Forms nuget package includes the CocosSharpView class, which is used to host CocosSharp in Xamarin.Forms. Add the CocosSharp.Forms NuGet and CocosSharp will be automatically added as well. To do this, right-click on the Packages folder in the .NET Standard library project and select Add Packages…. Enter the search term CocosSharp.Forms, select CocosSharp for Xamarin.Forms, then click Add Package.


Both CocosSharp and CocosSharp.Forms NuGet packages will be added to the project

Adding CocosSharp to a Xamarin.Forms app
Follow these steps to add a simple CocosSharp view to a Xamarin.Forms app:

Creating a Xamarin Forms Page

  1. Creating a Xamarin Forms Page
  2. Adding a CocosSharpView
  3. Creating the GameScene
  4. Adding a Circle
  5. Interacting with CocosSharp

Once you’ve successfully added a CocosSharp view to a Xamarin.Forms app, visit the CocosSharp documentation to learn more about creating content with CocosSharp.You can find more creative samples here.