前端之家收集整理的这篇文章主要介绍了
Cocos2d之CCScene,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CCScene是场景类,它相当于一个大容器,将包含在内的层和精灵输出到屏幕上,是整个树的根节点。其实CCScene的内部构成非常简单,虽然继承自CCNode,但没有在它的基础上增加任何成员变量和方法,只是重构了init。由此可以看出,其实CCScene并没有屏显的作用,其实它的作用只是承上启下,之前说过,节点只有被加到树中才会更新逻辑以及绘制,绘制的方法visit是节点实现的,场景只是把节点添加到树中使其可以执行该函数,然后导演类激活场景实例,使它构成的树生效(树可以有多个,但只有导演类激活的树才有效,在cocos2d中导演类最多只能激活一个树)。它用setContentSize方法将屏幕的尺寸传递给场景,使其默认和屏幕一样大,将锚点设置为(0.5,0.5)并将其锁定。
CCScene is a subclass of CCNode that is usedonly as an abstract concept.
CCScene an CCNode are almost identical withthe difference that CCScene has its
anchor point (by default) at the center of thescreen.
For the moment CCScene has no other logic thanthat,but in future releases it might have
additional logic.
It is a good practice to use and CCScene asthe parent of all your nodes.
@implementation CCScene
-(id) init
{
if( (self=[super init]) ) {
CGSize s = [[CCDirectorsharedDirector] winSize];
self.ignoreAnchorPointForPosition= YES;
anchorPoint_ = ccp(0.5f,0.5f);
[self setContentSize:s];
}
return self;
}
@end