Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hello CocosSharp

Hello CocosSharp

Mike Bluestein

October 11, 2014
Tweet

More Decks by Mike Bluestein

Other Decks in Technology

Transcript

  1. “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
  2. What Makes Up the Game • Application • Scenes •

    Layers • Sprites • Actions • Other cool stuff - Particle systems, audio, physics …
  3. CCApplication • Creates and initializes the graphics device • Sets

    the application delegate • Starts the game
  4. var app = new CCApplication (); 
 app.ApplicationDelegate = new

    GoneBananasApplicationDelegate ();
 app.StartGame (); CCApplication
  5. • Handles application lifecycle • Similar to UIApplicationDelegate in iOS

    • Set the application’s content folder • Load the main window’s first scene CCApplicationDelegate
  6. public virtual void ApplicationDidEnterBackground (CCApplication application)
 
 public virtual void

    ApplicationDidFinishLaunching (CCApplication application, CCWindow mainWindow)
 
 public virtual void ApplicationWillEnterForeground (CCApplication application)
 CCApplicationDelegate
  7. Content Folder Project Folder Containing Resources ▪ Fonts ▪ Sounds

    ▪ Images
 Set via application’s ContentRootDirector application.ContentRootDirectory = "Content";
  8. CCLayer • Added to scene • Contains node tree (sprites,

    labels, menus, etc) • Schedule method to run code at repeated interval • Creates the scene for which it is a child
  9. CCLayer var scene = new CCScene (mainWindow);
 var layer =

    new GameStartLayer ();
 scene.AddChild (layer);
 
 return scene;

  10. • Sprites are nodes that create images in the game

    • Image file must be in Content folder • Include high definition image using -hd convention CCSprite
  11. CCAction • Actions perform tasks on nodes • For example,

    animating sprites • Can run multiple actions sequentially using CCSequence
  12. CCTouch • Encapsulates a touch on the screen • Set

    TouchEnabled to true in layer • Override touch methods in layer ▪ TouchesBegan, TouchesMoved, TouchesEnded, etc
  13. Window.Accelerometer.Enabled = true;
 var listener = new CCEventListenerAccelerometer();
 listener.OnAccelerate =

    DidAccelerate;
 AddEventListener (listener); 
 
 public void DidAccelerate(CCEventAccelerate accelEvent)
 {
 accelEvent.Acceleration.X;
 accelEvent.Acceleration.Y;
 accelEvent.Acceleration.Z;
 }
 Accelerometer
  14. Audio • SimpleAudioEngine.SharedEngine ▪ Sound Effects ▪ Background Sound •

    Pause/Resume background sound in CCApplicationDelegate ▪ Pause when app enters background ▪ Resume when app enters foreground
  15. var draw = new CCDrawNode();
 
 draw.DrawPolygon(
 star, 
 star.Length,

    
 new CCColor4F(1, 0, 0, 0.5f), 1, 
 new CCColor4F(0, 0, 1, 1));
 
 Drawing Primitives
  16. Particle Systems • Graphical effects by rendering a set of

    particles • Several built in - smoke, galaxy, rain, … • Can add custom particle systems
  17. var sun = new CCParticleSun (pt);
 sun.StartColor = new CCColor4F

    (CCColor3B.Red);
 sun.EndColor = new CCColor4F (CCColor3B.Yellow); Particle Systems
  18. var sun = new CCParticleSun (pt);
 sun.StartColor = new CCColor4F

    (CCColor3B.Red);
 sun.EndColor = new CCColor4F (CCColor3B.Yellow); Particle Systems
  19. var parallaxClouds = new CCParallaxNode {
 Position = new CCPoint

    (0, h)
 };
 
 float yRatio1 = 1.0f;
 float yRatio2 = 0.5f;
 
 parallaxClouds.AddChild (cloud1, 0, 
 new CCPoint (1.0f, yRatio1), 
 new CCPoint (100, -100 + h - (h * yRatio1)));
 
 parallaxClouds.AddChild (cloud2, 0, 
 new CCPoint (1.0f, yRatio2), 
 new CCPoint (250, -200 + h - (h * yRatio2))); Parallax
  20. Effects • Lots of visual effects • Waves, Twirl, Lens3D,

    Shuffle Tiles, … • Implemented using actions
  21. var flipx = new CCFlipX3D(t);
 CCFiniteTimeAction flipx_back = flipx.Reverse();
 var

    delay = new CCDelayTime (2);
 
 return new CCSequence(flipx, delay, flipx_back); Effects
  22. Physics • 2D Rigid Body Physics • C# port of

    Box2D • world, body, shape, fixture
  23. var def = new b2BodyDef ();
 …
 b2Body body =

    world.CreateBody (def);
 var circle = new b2CircleShape ();
 …
 var fd = new b2FixtureDef ();
 fd.shape = circle;
 …
 body.CreateFixture (fd); Physics
  24. Gone Bananas Demonstrates Many CocosSharp Features ▪ Parallax ▪ Particles

    ▪ Touch handling ▪ Physics ▪ Sprite creation ▪ Actions ▪ Scene transitions ▪ Sprite sheet animation ▪ Sprite batching