Cocos2d Part 2 (Scenes, Layers)

 

 

+(CCScene *) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	HelloWorldLayer *layer = [HelloWorldLayer node];
	
	// add layer as a child to scene
	[scene addChild: layer];
	
    
    CCSprite *background = [CCSprite spriteWithFile:@"Default.png"];
    background.anchorPoint=ccp(0, 0);
    [layer addChild:background z:-1];
	// return the scene
	return scene;
}

// 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]) ) {
		CCSprite *head = [CCSprite spriteWithFile:@"head.png"];
        head.position=ccp(200, 200);
        [self addChild:head];
	
	}
	return self;
}

你可能感兴趣的:(cocos2d)