游戏主页面布局

哇!板球 源代码分析二_单对象

创建屏下Score标签

pLabel = CCLabelTTF::create("Score", "Arial", TITLE_FONT_SIZE);	 //分数标签
    //设置标签字体的颜色
    pLabel->setColor (ccc3(0, 0, 0));
    //设置文本标签的位置
    pLabel->setPosition
    (
    	ccp
    	(
			SCORE_X,					//X坐标
			SCORE_Y	                    //Y坐标
         )
    );
    //将文本标签加入到布景中
    this->addChild(pLabel, TOP_LEVEL);

创建屏下机会左边数字为0标签

overLabel = CCLabelTTF::create("0", "Arial", TITLE_FONT_SIZE);
	//设置标签字体的颜色
	overLabel->setColor (ccc3(255, 0, 0));
	//设置文本标签的位置
	overLabel->setPosition
	(
		ccp
		(
			OVERLABEL_X,				//X坐标
			SCORE_Y	                    //Y坐标
		 )
	);
	//将文本标签加入到布景中
	this->addChild(overLabel, TOP_LEVEL);

创建主页面背景

    CCSprite* pSprite = CCSprite::create("pic/background.png");	
    //设置精灵对象的位置
    pSprite->setPosition(ccp(origin.x, origin.y));
    pSprite->setAnchorPoint(ccp(0, 0));//默认锚点为0.5,0.5
    //将背景精灵加入到布景中
    this->addChild(pSprite, BACKGROUND_LEVEL_WYF);

创建左上角暂停键

	CCMenuItemImage *pauseMenuItem = CCMenuItemImage::create 
	(
	  "pic/pause.png",     //平时的图片
	  "pic/pause1.png",   //选中时的图片
	  this,
	  menu_selector(BanQiuLayer::pauseCallBack)//点击时运行的回调方法
	);
	//设置暂停菜单项的位置
	pauseMenuItem->setPosition(ccp(150,450));

	//创建菜单对象
	CCMenu* pauseMenu = CCMenu::create(pauseMenuItem, NULL);
	//设置菜单位置
	pauseMenu->setPosition(CCPointZero);
	//将菜单加入到布景中
	this->addChild(pauseMenu,DASHBOARD_LEVEL_WYF);

创建右側6号网

	CCSprite* sixSprite = CCSprite::create("pic/six.png");
	//设置精灵对象的位置
	sixSprite->setPosition(ccp(GRID_SIX_X, GRID_SIX_Y));
	sixSprite->setAnchorPoint(ccp(1, 0.5));//默认锚点为0.5,0.5
	//将背景精灵加入到布景中
	this->addChild(sixSprite, DASHBOARD_LEVEL_WYF);
创建上面的1、2号网

	CCSprite* oneTSprite = CCSprite::create("pic/one.png");
	//设置精灵对象的位置
	oneTSprite->setPosition(ccp(GRID_ONE_TOP_X, GRID_ONE_TOP_Y));
	oneTSprite->setAnchorPoint(ccp(1, 1));//默认锚点为0.5,0.5
	//将背景精灵加入到布景中
	this->addChild(oneTSprite, DASHBOARD_LEVEL_WYF);
	CCSprite* twoTSprite = CCSprite::create("pic/two.png");
	//设置精灵对象的位置
	twoTSprite->setPosition(ccp(GRID_TWO_TOP_X, GRID_TWO_TOP_Y));
	twoTSprite->setAnchorPoint(ccp(1, 1));//默认锚点为0.5,0.5
	//将背景精灵加入到布景中
	this->addChild(twoTSprite, DASHBOARD_LEVEL_WYF);

创建以下的1、2号网

	CCSprite* oneBSprite = CCSprite::create("pic/one.png");
	//设置精灵对象的位置
	oneBSprite->setPosition(ccp(GRID_ONE_BOTTOM_X,GRID_ONE_BOTTOM_Y));
	oneBSprite->setAnchorPoint(ccp(1, 0));//默认锚点为0.5,0.5
	//将背景精灵加入到布景中
	this->addChild(oneBSprite, DASHBOARD_LEVEL_WYF);
	CCSprite* twoBSprite = CCSprite::create("pic/two.png");
	//设置精灵对象的位置
	twoBSprite->setPosition(ccp(GRID_TWO_BOTTOM_X,GRID_TWO_BOTTOM_Y));
	twoBSprite->setAnchorPoint(ccp(1, 0));//默认锚点为0.5,0.5
	//将背景精灵加入到布景中
	this->addChild(twoBSprite, DASHBOARD_LEVEL_WYF);
创建主角球拍

	CCSprite* sachinSprite = CCSprite::create("pic/sachin.png");
	//设置精灵对象的位置
	sachinSprite->setPosition(ccp(PLAYER_X,PLAYER_Y));
	sachinSprite->setAnchorPoint(ccp(0, 0));//默认锚点为0.5,0.5
	//将背景精灵加入到布景中
	this->addChild(sachinSprite, GAME_LEVEL_WYF);
创建最底部的图片, 充当仪表盘
CCSprite* tickerSprite = CCSprite::create("pic/ticker.png");
	//设置精灵对象的位置
	tickerSprite->setPosition(ccp(BOARD_X,BOARD_Y));
	tickerSprite->setAnchorPoint(ccp(0, 0));//默认锚点为0.5,0.5
	//将仪表盘精灵加入到布景中
	this->addChild(tickerSprite, DASHBOARD_LEVEL_WYF);

定义2个定时器,用来检測碰撞和置道具出场标志

    this->schedule(schedule_selector(BanQiuLayer::upDate),0.01f);//碰撞检測
    this->schedule(schedule_selector(BanQiuLayer::setOutPropFlag),5);//5秒道具出场


创建屏幕其它文本标签

机会右側文本标签

CCLabelTTF *over ;
	char o[5];
	snprintf(o, 5, "%d",6-guanka);
	std::string overStr = "/ ";
	overStr=overStr+o;
	over = CCLabelTTF::create(overStr.c_str(), "Arial", TITLE_FONT_SIZE);
	//设置标签字体的颜色
	over->setColor (ccc3(250, 0, 0));
	//设置文本标签的位置
	over->setPosition
	(
		ccp
		(
			OVERLABEL_X+40,				//X坐标
			SCORE_Y	                    //Y坐标
		 )
	);
	//将文本标签加入到布景中
	this->addChild(over, TOP_LEVEL);

创建目标分数标签,每一关乘以50

CCLabelTTF *targetLabel ;
	char s[5];
	snprintf(s, 5, "%d",guanka*50);
	targetLabel = CCLabelTTF::create(s, "Arial", TITLE_FONT_SIZE);
	//设置标签字体的颜色
	targetLabel->setColor (ccc3(250, 0, 0));
	//设置文本标签的位置
	targetLabel->setPosition
	(
		ccp
		(
			TARGETLABEL_X,				//X坐标
			SCORE_Y	                    //Y坐标
		 )
	);
	//将文本标签加入到布景中
	this->addChild(targetLabel, TOP_LEVEL);

创建关卡标签

	CCLabelTTF *gk ;
	char g[5];
	snprintf(g, 5, "%d",guanka);
	gk = CCLabelTTF::create(g, "Arial", TITLE_FONT_SIZE);
	//设置标签字体的颜色
	gk->setColor (ccc3(250, 0, 0));
	//设置文本标签的位置
	gk->setPosition(ccp(720,SCORE_Y));
	this->addChild(gk, TOP_LEVEL);


设置守门员出场的频率, 关卡数越高出场频率越快

this->schedule(schedule_selector(BanQiuLayer::setOutFielderFlag),(6-guanka)/2.0f);