Tweaked to make it compatible with cocos2d 2.1