int main (int argc, char ** argv) { nvInit(); menuInit(); NavEvent nav; while (1) { nav = navWaitForEvent(); switch (nav) { case NAV_LEFT: menuLeft(); break; case NAV_RIGHT: menuRight(); break; case NAV_UP: menuUp(); break; case NAV_DOWN: menuDown(); break; //case NAV_TAP: menuSelect(); break; case NAV_ACCESS_1: case NAV_ACCESS_2: case NAV_HOTKEY_1: case NAV_HOTKEY_2: case NAV_HOTKEY_3: case NAV_HOTKEY_4: case NAV_HOTKEY_5: case NAV_HOTKEY_6: case NAV_HOTKEY_7: case NAV_HOTKEY_8: case NAV_HOTKEY_9: default: printf("Unknown NAV option\n"); return 1; break; } } }
bool ScrollMenu::init(std::vector<CCSprite*> nodes) { isTouchable = true; btns = nodes; arrowColor = PH::GetSprite("gameui/fangxiang_daohang.png"); addChild(arrowColor); arrowGray = PH::GetSprite("gameui/fangxiang_daohang2.png"); addChild(arrowGray); std::vector<CCSprite*> btnsToScroll; for(CCSprite* btn : btns) { cocos2d::CCSprite* btnBg = PH::GetSprite("gameui/yuandi.png"); btn->setPosition(ccp(btnBg->getContentSize().width*0.5f, btnBg->getContentSize().height*0.5f)); btnBg->addChild(btn); btnsToScroll.push_back(btnBg); } scrollView = PageScrollView::create(btnsToScroll,CCSizeMake(110, 100),false); scrollView->setViewPort(CCRectMake(-60, 0, 550, 120)); scrollView->setPositionX(45); addChild(scrollView); scrollView->setTouchEnabled(false); menuLeft(); return true; }
void ScrollMenu::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) { CCSet set; set.addObject(pTouch); scrollView->ccTouchesEnded(&set, pEvent); if(scrollView->getCurrentNodeId() == 0) menuLeft(); else if(scrollView->getCurrentNodeId() == scrollView->endNodeIndex) menuRight(); }