Cocos2D-XNA Tutorial 0: Getting Started

This is the first post in a series (at least that’s the plan) on learning to use the Cocos2d-XNA framework.  My goal in writing this series is two-fold: to help myself understand how to use this framework and by extension, to help others learn from my learning (and mistakes, which will probably be many, at least starting out :)).  The Cocos2D-XNA Learning References post contains a list of the references I’ve used to learn Cocos2d-XNA if you’re interested.  Well, it’s time to forge ahead and see what I can do.

If you’ve never heard of Cocos2D-XNA, it is a port of the Cocos2d framework (it originated on Apple’s iOS for iPhone / iPad development) to MonoGame’s cross-platform XNA API, so you get to program in C#, XNA, and Cocos2D goodness… which I think is pretty freakin’ sweet.

To get started, we need to get our environment setup to run the coolness.  I’m going to point you to the resources I used to get setup instead of trying to detail all of that stuff here:

Once you complete the above steps, you should be able to create a test application in Visual Studio with one of the Cocos2D-XNA templates (I’m using the Windows GL template), compile it, and run it successfully… your basic Hello World! app for Cocos2D-XNA.  If you’re running into problems, go back over the steps above and make sure you didn’t miss a step.

Now, the standard template gets you setup to work on a game using the appropriate binary assemblies for Cocos2D-XNA and MonoGame, which is fine.  However, if you’re like me, I like having all the code available in my solution so when I’m debugging, I can see what’s going on under the hood.  If you’d like to do the same, here’s what I did to get that setup:

  • If you don’t already have it, install GitHub for Windows on your computer.  You can get the repositories manually from GitHub if you like, but the instructions below assume you’ve installed the Git for Windows application.
  • Open a Git Shell prompt and change to a location on your drive where you want to store the repositories (e.g. C:\GitRepos).
  • Head over to the Cocos2D-XNA GitHub page and have a look at the at the bottom of the page for instructions on how to install the source code properly.
  • Create a new Cocos2D-XNA game project in Visual Studio.

Create New Cocos2D-XNA Project

  • Remove the box2d, cocos2d-xna, Lidgren.Network, and MonoGame.Framework references from your  project.

Cocos2D-XNA Solution References

  •  Add the box2d, cocos2d-xna, Lidgren.Network, and MonoGame.Framework projects to the solution from the MonoGame and Cocos2D-XNA repositories.  There are several projects for MonoGame and Cocos2D-XNA, so you need to select the correct project type based on the platform you’re targeting.  For example, if you made a Windows GL Cocos2D-XNA game, you would add the following projects to your solution:

Add VS Project Dialog

  • In your game project, add a project reference to the box2d, cocos2d-xna, Lidgren.Network, and MonoGame.Framework projects.

Add Project References

  • Compile your solution and verify that it builds successfully.  If so, you should be all set.  If not, make sure you added the references in the order shown above.  I initially had an issue with the Cocos2D-XNA project generating a ton of errors that made no sense, like it was missing the MonoGame reference even though it was pointing to the correct location.  I removed the project reference and added it back, and poof… no more errors.  So I’m thinking it was an ordering problem of how I added the projects and/or project references.

After getting all that setup, I was able to break through my game code, as well as all the applicable framework code.  Now I’m ready to get going on some game development with Cocos2D-XNA and hopefully you are too.  Happy proggy.


You May Also Like

About the Author: ricke


  1. Thank you very much for these tutorials, they are extremely helpful, and the project files on github are also a great resource. Cant be grateful enough!!

  2. Nice tutorial, very handy!
    Do you have any thoughts about doing a tutorial explaining how to load a Tiled archive (.tmx)? I’m debugging the source, like you said, but when the code goes to the line when it should load the .xnb that I generated, the texture is always null!?
    Man, don’t give up your tutorials, please!!! 🙂

    1. Hi, Mário. I’m glad you found it helpful. I have only looked at Tiled briefly and haven’t had time to play with it yet… it looks pretty cool. I’d say your best bet on getting help with it for now would be to post on the Cocos2d-XNA forum, they would be far more knowledgeable at this point. 🙂 I’m planning to do more tutorials when I have time, they have been fun to write. 🙂

Leave a Reply to ricke Cancel reply

Your email address will not be published. Required fields are marked *