abitofcode

May 9, 2012
by Chris
5 Comments

Cocos2d – Getting started


The following is a list of links and resources that should make finding your way around Cocos2d a little easier.

Beware of older code examples and tutorials when looking for help, a lot changed between Cocos2d v0.82 and v1.0 including the names of a lot of the framework methods.

The simplest way to find which version a project is using is to open up the cocos2d.m file and look for the version string

static NSString *version = @"cocos2d v1.1.0-beta2b";

IMHO the best way to get into Cocos2d is to build something with it. Don’t look at the resources below as something you have to finish before you begin or you’ll never get started ;)

In no particular order;
Continue Reading →

May 7, 2012
by Chris
12 Comments

So what happened to Sketchshare?

After nearly 3 months on the App Store, we received a very short phone call from Apple. Submit an update of Sketchshare without Game Centre functionality or the App will be removed from the store, you have 2 days to comply. So two days to attempt to implement a Game Center alternative complete with VoIP or remove the sharing functionality from existing Sketchshare users. Neither option was really viable and so 2 days later Apple removed it from Sale.
Continue Reading →

April 30, 2012
by Chris
7 Comments

CCRenderTexture category – percentage complete

Here’s a Category to return the percentage of a CCRendertexture that is transparent i.e what percentage of the pixels have an alpha value of zero. Question originally asked on cocos2d forum.

I’ve thrown together a quick example project where a country scene is scratched off to reveal the same location in colder times, once the entire image is scratched off the percentage transparent should be 100 (download available at bottom of post)

Tap the image 3 times to reset.


Continue Reading →

March 14, 2012
by Chris
Comments Off

TimeScroller widget

For anyone who has to occasionally schedule a meeting or phone call across time zones TimeScroller is a great little widget and it’s free!

It defaults to the current time but a great feature is the slider at the bottom that allows you to slide forward in time and watch all the zones update. The widget allows you to configure your preferred zones and the order they appear. There is also an email button that will take all the time zones you have set for the current slider time and copy them into an email.

There’s a paid iPhone version if you need a mobile version.

March 3, 2012
by Chris
1 Comment

Sherbert fountain based Infrared marker

I spent some time a couple of years ago playing with Johnny Chungs idea for a wii remote driven interactive whiteboard. I didn’t have a projector so I used the screen from my 24″ iMac and I cobbled together an infrared pen using not much more than sticky tape.
With a planned desktop version of Sketchshare waiting in the wings I decided it was time to resurrect my whiteboard experiments. The further nudge I needed happened when my wife bought me a Sherbert fountain.

The end result


Continue Reading →

February 23, 2012
by Chris
Comments Off

Python shortcut for animation plists

Quick (and not too pretty) python script I threw together for generating animation frame plists. For a tutorial about using the plist to drive your cocos2d animation check out this great tutorial from Ray Wenderlich’s site.

I had a list of 208 separate frames of animation that were added to a sprite map as part of the build in XCode using TexturePacker.

There are a number of assumptions made about the animations but at least the script should save some time on the initial creation.
* Each animation frame file starts with a name that will become the name of the plist.
* Frames have a sequence number after a ‘_’ that is used to determine the order.
* The sequence does not have to be continuous i.e 00002, 00003, 00006 is fine
* Don’t put anything in the directory that you are loading the images from that is not an image.

import sys
import os
 
def writePlist(fileName, content):    
    # Create a file object:
    # in "write" mode
    FILE = open(fileName,"w")
    header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
    header += "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
    header += "<plist version=\"1.0\">\n<array>\n"
    content = header + content + "</array>\n</plist>"
 
    # Write all the lines at once:
    FILE.writelines(content)
 
    FILE.close()
 
# If no database is specified, drop out
if len(sys.argv) < 2:
    sys.exit('Usage: %s directoryOfImages' % sys.argv[0])
 
# Get the path to the directory of images
imageDir = sys.argv[1] + '/'    
 
 
if not os.path.exists(imageDir):    
    sys.exit('Directory: %s does not exist' % imageDir)    
 
fileName=""
fileContents=""
 
listing = os.listdir(imageDir)
for infile in listing:
    fileParts = infile.split("_")
    fileStub = fileParts[0]    
    if fileStub != fileName:
        if fileName != "":
            writePlist(fileName + ".plist", fileContents)              
        fileName = fileStub
        fileContents = "\t<string>" + infile + "</string>\n"
    fileContents+= "\t<string>" + infile + "</string>\n"
 
#write the last file
writePlist(fileName + ".plist", fileContents)

To use it (assuming you named it plist.py)

>ls -la safe_png
drwxr-xr-x 210 abitofcode staff 7.0K 23 Feb 21:54 ./
drwxr-xr-x 27 abitofcode staff 918B 23 Feb 15:50 ../
-rw-r–r–@ 1 abitofcode staff 17K 23 Feb 13:11 hookDead_00001.png
-rw-r–r–@ 1 abitofcode staff 22K 23 Feb 13:11 hookDead_00002.png
-rw-r–r–@ 1 abitofcode staff 21K 23 Feb 13:11 hookDead_00003.png
-rw-r–r–@ 1 abitofcode staff 22K 23 Feb 13:11 hookDead_00004.png
-rw-r–r–@ 1 abitofcode staff 21K 23 Feb 13:11 hookDead_00005.png
-rw-r–r–@ 1 abitofcode staff 21K 23 Feb 13:11 hookDead_00006.png
-rw-r–r–@ 1 abitofcode staff 22K 23 Feb 13:11 hookDead_00007.png
-rw-r–r–@ 1 abitofcode staff 22K 23 Feb 13:11 hookDead_00008.png
-rw-r–r–@ 1 abitofcode staff 22K 23 Feb 13:11 hookDead_00009.png
-rw-r–r–@ 1 abitofcode staff 22K 23 Feb 13:11 hookDead_00010.png
-rw-r–r–@ 1 abitofcode staff 22K 23 Feb 13:11 hookDead_00011.png
-rw-r–r–@ 1 abitofcode staff 21K 23 Feb 13:11 hookDead_00012.png

>python plist.py safe_png

The above example would generate a single plist called hookDead.plist with 12 entries but the script can be run against whole directories of files.

Download the files here: Python animation Plist builder

January 27, 2012
by Chris
1 Comment

Cocos2d Cookbook

Nathan Burba has done a fantastic job of pulling together a great collection of recipes for the cocod2d cookbook covering everything from Bullets to Speech recognition.
Once Sketchshare is fully launched I plan on doing a review of the book in some detail. In the meantime it’s perfect for the Inquisitive/Intermediate programmer and covers a wide variety of techniques. For further detail check out Nathans site http://cocos2dcookbook.com/ which has videos detailing the techniques covered in the book.

It’s available to purchase over at Packt’s site

%d bloggers like this: