该函数演示的是:旋转功能
@implementation MainLayer
-(id) init
{
if( ! [super init] )
return nil;
float x,y;
CGSize size = [[Director sharedDirector] winSize];
x = size.width;
y = size.height;
//ColorLayer是实现CocosNodeRGBA的子层,他除了有Layer的所有功能之外,
//并且有以下特征:opacity(不透明) RGB颜色
CocosNode* blue = [ColorLayer layerWithColor:ccc4(0,0,255,255)];
CocosNode* red = [ColorLayer layerWithColor:ccc4(255,0,0,255)];
CocosNode* green = [ColorLayer layerWithColor:ccc4(0,255,0,255)];
CocosNode* white = [ColorLayer layerWithColor:ccc4(255,255,255,255)];
[blue setScale: 0.5f];
//注意:x= size.width,-x -y:表示在左下角
[blue setPosition: ccp(-x/4,-y/4)];
//增加SpriteLayer场在blue中
[blue addChild: [SpriteLayer node]];
//x -y(右下角)
[red setScale: 0.5f];
[red setPosition: ccp(x/4,-y/4)];
//-x y(左上角)
[green setScale: 0.5f];
[green setPosition: ccp(-x/4,y/4)];
[green addChild: [TextLayer node]];
//x y(右上角)
[white setScale: 0.5f];
[white setPosition: ccp(x/4,y/4)];
[self addChild: blue z:-1];
[self addChild: white];
[self addChild: green];
[self addChild: red];
//定义旋转方法:角度为:720 时间为8秒
Action * rot = [RotateBy actionWithDuration:8 angle:720];
[blue runAction: rot];
[red runAction: [[rot copy] autorelease]]; //完成后自动release
[green runAction: [[rot copy] autorelease]];
[white runAction: [[rot copy] autorelease]];
return self;
}