在我们创建一个cocos-2d模板之后,系统自动生成一个场景Demo,运行结果显示HelloWord
创建一个cocos2d ios工程
运行结果,我们点击Achievments 和 LeaderBoard 会分别跳转到其他场景
创建工程里面目录结构
上面的六个.h和.m文件如果需要实现某功能是需要开发者在里面编辑代码的,Resouces文件夹用于存放图片,声音文件文字文件plist文件等文件,这样组织便于我们进行管理工程里面文件;libs下的文件就是cocos2d引擎了,存放的是源文件,因为它属于开源,所以可以看到他底层实现原理;还有常用的framework框架
生成的第一个HelloWord代码实现全都在HelloWorldLayer.h HelloWorldLayer.h和HelloWorldLayer.m文件中-(id)initf方法中,贴上他的源代码
// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super init]) ) {
// create and initialize a Label
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
// ask director for the window size
CGSize size = [[CCDirector sharedDirector] winSize];
// position the la