今天做个贪吃蛇的游戏,里面需要用到单选按钮选择速度,但从网上找了找,没有找到cocos2d-x的实现方法,但是有cocos2d-iphone的实现方法,由于本人之前学过ios的基本开发,有OC语言有些了解,而且也学过C++,所以就将cocos2d-iphone的实现方法重写了一遍,在此分享给大家:,.
使用方法:
CCMenuItemImage *bu01 = CCMenuItemImage::create("veryfast.png", "veryfastsel.png", this, menu_selector(GameSetting::button1CallBack)); CCMenuItemImage *bu02 = CCMenuItemImage::create("faster.png", "fastersel.png", this, menu_selector(GameSetting::button2CallBack)); CCMenuItemImage *bu03 = CCMenuItemImage::create("middle.png", "middlesel.png", this, menu_selector(GameSetting::button3CallBack)); CCMenuItemImage *bu04 = CCMenuItemImage::create("slow.png", "slowsel.png", this, menu_selector(GameSetting::button4CallBack)); CCRadioMenu *radioMenu = CCRadioMenu::create(bu01,bu02,bu03,bu04,NULL); radioMenu->setPosition(ccp(480.0, 500.5));//480.0, 590.0 radioMenu->alignItemsHorizontally(); radioMenu->setSelectedItem_(bu01); bu01->selected(); this->addChild(radioMenu, 1);