Kobold2D HowTo – making a new template for Cocos2D apps

For a new project, I’m learning Cocos2D, and for this I’m using Steffan Itterheim’s Kobold project.  It’s pretty cool.  You hit the Kobold2D Project Starter app, select a template to work with and a name for your app, and hit go…. it builds a basic Cocos2D app for you, ready and working, and formatted to compile for iPhone or iPad, and in many cases for OS-X compilation (not all Cocos2D features will work – YMMV).

So far, I’m finding Kobold2D (and Cocos2D) pretty nice.  But what I wanted to do was build a whole series of test apps that will provide the building blocks I need for future development.  Like… there’s no way in Cocos2D to make a text box that displays formatted HTML.  So what you need to do is use a UIWebView… but tied into Cocos2D somehow.  Kobold2D has a sample template that shows one way to do this, and I used that as a starting point, but it seems cludgy to me.

So I went looking and found CCUIViewWrapper, an extension for Cocos2D that seems to do pretty much what I want… just instantiate a UIWebView and build a wrapper around it and add the HTML code into it that you want.  I’ll probably write another post about that (cause it’s nice), but this post is because I want now to put a new template into the Kobold builder that includes all the extra stuff I want (and none of the Kobold stuff I don’t) and use this new template for my next building block explorations.

So I read Steffen’s “Creating a Kobold2D Template Project” page, and didn’t quite get it.  The nuggets are there, but it’s not a step-by-step, so I’m making one here, in case you’re looking for one.

1. Read his “Creating” page first.  Pay attention to the naming section.

2. Use his Kobold2D Project Starter app to start a new project.  Pick one that’s close to what you want.  Name it according to the rules in Step 1, like “_My-First-Attempt-Template_”.  Key: it starts with an underscore, and ends with “-Template_” and everything inside is just alphanumeric text and hyphens, nothing fancy.

[EDIT]   (A LATER NOTE) Also, I’ve found that any hyphen-separated parts of the name should be Capitalized.  Like “_My-second-attempt-Template_” may not work, whereas “_My-Second-Attempt-Template_” would.  I did this wrongly, and the template never showed up in the Kobold2D Project Starter menu!  [/END EDIT]

3. That should open you into Xcode with your new project started.  The first thing is to compile it with one of the simulators, like the ones you’re aiming for.  This is just to be sure it works.  It should.

4. Change the source codes to whatever you want.  Compile along the way, making sure it all works.  Add resources, etc.  Make sure everything you need is copied into the template folder so it doesn’t rely on outside things, unless that’s the way you want to roll.

5. When you’re satisfied, you’re done here.  Go to the Finder and find the the _My-First-Attempt-Template_ folder you’ve been working on.  Copy that entire folder over to the __Kobold2D__/templates/project folder.  That will allow Kobold2D to find and display it as one of it’s templates.

6.  Open the _My-First-Attempt-Template_.xcodeproj to see the Package contents (right click on it in Finder, choose “Show Package Contents”.  In this package, delete the “xcuserdata” folder (this is not needed, and will give the wrong scheme names in your new templated projects if it is not deleted).

7.  Add a new plain text file in the root of the _My-First-Attempt-Template_ folder called “_description_”.  Write a brief description of the template in this file.

8. Try it!  Run Kobold project starter and it should let you make a new project just the way you want it with your new template.  Test the new project thoroughly to see it works right.  It should.

9. Use your new template yourself, or share with everyone else by giving your code an MIT open source license and release it on github and tell Steffan about it.  If it’s useful, he says he’ll consider packaging it up with his templates too.

 

 

 

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>