Example #1
0
bool CGameLevel::init()
{
	LayerBack::init();

	g_iGameLevel = 1;
	size = winSize;


	// 选关列表
	SpriteFrameCache *pCache = SpriteFrameCache::sharedSpriteFrameCache();
	pCache->addSpriteFramesWithFile("Image/GameLevel.plist");

	// 选关背景
	SpriteFrame* pBG = pCache->spriteFrameByName("GameLevelBG.png");
	Sprite* pSprite = CCSprite::createWithSpriteFrame(pBG);
	pSprite->setPosition(ccp(size.width/2, size.height/2));
	pSprite->setScale(2.0f);
	pSprite->setRotation(90.0f);
	this->addChild(pSprite, 0);
	_pSprite = pSprite;
		
	/**背景特效	*/
	ParticleSystemQuad *emitter = ParticleSystemQuad::create("Image/Phoenix.plist");
	emitter->setPosition(ccp(size.width/2, size.height/2));
	this->addChild(emitter, 1);

	/**	关卡一按钮	*/
	MenuItemImage *pLevelOne = MenuItemImage::create();
	pLevelOne->setTarget(this, menu_selector(CGameLevel::setLevelMode));
	pLevelOne->setNormalSpriteFrame(pCache->spriteFrameByName("StartLevel1Normal.png")); 
	pLevelOne->setSelectedSpriteFrame(pCache->spriteFrameByName("StartLevel1Selected.png"));
	pLevelOne->setPosition(ccp(size.width*0.14f, size.height/2));
	pLevelOne->_ID = LEVEL_ONE;

	/**	关卡二按钮	*/
	MenuItemImage *pLevelTwo = MenuItemImage::create();
	pLevelTwo->setTarget(this, menu_selector(CGameLevel::setLevelMode));
	pLevelTwo->setNormalSpriteFrame(pCache->spriteFrameByName("StartLevel2Normal.png")); 
	pLevelTwo->setSelectedSpriteFrame(pCache->spriteFrameByName("StartLevel2Selected.png"));
	pLevelTwo->setPosition(ccp(size.width/2, size.height*0.8f));
	pLevelTwo->_ID = LEVEL_TWO;

	/**	关卡三按钮	*/
	MenuItemImage *pLevelThree = MenuItemImage::create();
	pLevelThree->setTarget(this, menu_selector(CGameLevel::setLevelMode));
	pLevelThree->setNormalSpriteFrame(pCache->spriteFrameByName("StartLevel3Normal.png")); 
	pLevelThree->setSelectedSpriteFrame(pCache->spriteFrameByName("StartLevel3Selected.png"));
	pLevelThree->setPosition(ccp(size.width*0.86f, size.height/2));
	pLevelThree->_ID = LEVEL_THREE;

	/**	游戏开始按钮	*/
	MenuItemImage *pStart = MenuItemImage::create();
	pStart->setTarget(this, menu_selector(CGameLevel::setLevelStart));
	pStart->setNormalSpriteFrame(pCache->spriteFrameByName("GameStartNormal.png")); 
	pStart->setSelectedSpriteFrame(pCache->spriteFrameByName("GameStartSelected.png"));
	pStart->setPosition(ccp(size.width/2, size.height*0.2f));

	/**	菜单	*/
	_menu->addChild(pLevelOne);
	_menu->addChild(pLevelTwo);
	_menu->addChild(pLevelThree);
	_menu->addChild(pStart);
	_menu->setPosition(ccp(0, 0));
	_menu->setZOrder(3);

	/**	选中特效	*/
	m_pSun = ParticleSun::create();
	pSprite->addChild(m_pSun, 1);
	m_pSun->setTexture(TextureCache::sharedTextureCache()->addImage("Image/Fire.png") );
	m_pSun->setPosition(_pSprite->convertToNodeSpace(ccp(size.width*0.14f, size.height / 2)));
	m_pSun->setStartSize(30);

	_menuItem->setTarget(this, menu_selector(CGameLevel::back));
	//_menuItem死活不出现

	return true;
}