Presented at NDC Oslo
C# has become one of the most prolific languages used in game development. Games developed in C# can be created to target desktops, tablets, mobile devices and game consoles, while sharing nearly the entire code base. On mobile devices 2D games in particular are massively popular. In this session, we'll explore how to use C# in conjunction with Microsoft and Xamarin to develop 2D games that will work on iOS, Android and Windows platforms. We'll cover the basics of 2D game development, working with multiple scenes, animation and even physics. By the end of the session, you'll have seen how to make a cross-platform 2D game that you can use as the basis for creating your own games.
5. Shared C# codebase • 100% native API access • High performance
iOS C# UI Windows C# UIAndroid C# UI
Shared C# Mobile
6. Building Games with Xamarin
§ MonoGame
Apple Toy Car Sample -‐ WWDC 2014Angry Ninjas
Sample
§ Mono for Unreal Engine
§ Sprite Kit
§ Scene Kit
§ CocosSharp
7. What is CocosSharp?
“CocosSharp blends the power of the
Cocos2D programming model with C# and
the .NET Framework…the API has been
designed to follow C# and .NET idioms.”
Miguel de Icaza
Xamarin
8. Where it came from
Cocos2D
Objective-‐C
Cocos2D-‐x
C++
Cocos2D-‐XNA
C#
CocosSharp
C#
§ .NET Idioms
§ Naming, Constructors, C#ier
§ Global State -> Multiple Directors
§ Actions as Immutable
§ NuGet & PCL Libraries
§ Extensions + Sanitized Hierarchy
§ Events, Coloring, Labels, & More
11. CCApplication
§ Creates & Initializes the Graphics Device
§ Sets the application delegate
§ Starts the Game
var app = new CCApplication ();
app.ApplicationDelegate = new MyGameDelegate ();
app.StartGame ();
12. CCApplicationDelegate
§ Handles application lifecycle
§ Similar to UIApplicationDelegate on iOS
§ Sets the application’s content folder
§ Load the main window’s first scene
public virtual void ApplicationDidEnterBackground
public virtual void ApplicationDidFinishLaunching
public virtual void ApplicationWillEnterForeground
14. CCDirector
§ Available via Window.DefaultDirector
§ Manages any additional scene loading
Window.DefaultDirector.ReplaceScene (
GameLayer.GameScene (Window));
15. CCScene
§ Manages game logic for various portions
of your game
§ Contains layers (CCLayer)
16. CCLayer
§ Contains CCNodes
§ Labels, Sprites, Menus, and more
var scene = new CCScene (mainWindow);
var layer = new GameStartLayer ();
scene.AddChild (layer);
17. CCSprite
§ Nodes that create images in your game
§ Image file must be in a Content folder
§ DefaultTexelToContentSizeRatio(s)
§ Used to maintain content across
resolutions
18. CCAction
§ Actions perform tasks on nodes
§ For example, animating sprites
§ Run multiple actions sequentially using
CCSequence
§ Run multiple actions in parallel using
CCSpawn
19. CCTouch
§ Encapsulates a touch on the screen
§ Override touch methods in layer
§ TouchesBegan, TouchesMoved,
TouchesEnded, etc.
§ All touches at once
§ Each touch one by one
20. So Much More
§ Accelerometer
§ Audio
§ Primitives
§ Particle Systems
§ Parallax
§ Effects
§ Physics
24. Free trial - xamarin.com/university
Unrivaled Mobile
Development
Training
Live unlimited mobile development training from
mobile experts, in your time-zone,on your
schedule, and as often as you'd like.