首页 > 代码库 > 哇!板球 源码分析二
哇!板球 源码分析二
游戏主页面布局
创建屏下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秒道具出场
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。