_大多数情况下,在cocos2d的初始化过程中,只有三个设置你可能会改变:
[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];//设备方向
[[CCDirector sharedDirector] setAnimationInterval:1.0/60];//它表示的是cocos2d更新屏幕的频率
[[CCDirector sharedDirector] setDisplayFPS:YES];//显示帧每秒(FPS)
所有节点的基类都是CCNode类。它包含了位置信息,但是没有显示信息。它是 所有其他节点类的父类,包括两个最基本的类:CCScene和CCLayer。
CCScene是一个抽象的概念,它的功能是根据像素坐标把物体放置在场景里相应 的地方。所以任何cocos2d场景都会用一个CCScene作为父对象。
CCLayer类本身并不做什么,它的功能是允许触摸和加速计的输入。因为大多数 游戏会接受基本的触摸输入,所以CCLayer通常是第一个被加入CCScene的类。
// 生成并初始化标签对象
CCLabel* label = [CCLabel labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
// 从CCDirector得到窗口的尺寸
CGSize size = [[CCDirector sharedDirector] winSize];
// 将标签放在屏幕中央
label.position = CGPointMake(size.width / 2, size.height / 2);
// 将标签作为子节点添加到场景层中
[self addChild: label];
大多数 cocos2d 对象都是自动释放对象。
,self.isTouchEnabled被设为YES。这是CCLayer的一个属性,它告诉系统 你的程序想接受触摸信息。只有这样ccTouchBegan才会被调用:
-(void) ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event; {
CCLabel* label = (CCLabel*)[self getChildByTag:13];
label.scale = CCRANDOM_0_1();
}
//CCLabel 在1。01版本上已经改为CCLabelTTF