您的位置:首页 > 移动开发 > Cocos引擎

Cocos2d之CCScene

2015-02-13 23:18 246 查看
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.

#import "CCScene.h"
#import "Support/CGPointExtension.h"
#import "CCDirector.h"

@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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocos2d CCScene