1
头文件
TMenu.h |
#ifndef __TMENU_H__ #define #include USING_NS_CC; class { public: static CREATE_FUNC(TMenu); bool CCMenu * void void virtual virtual }; #endif |
TMenu.cpp |
#include "TMenu.h" #include #include #include #include #include #include #include #include #include #include //通过sizeof(menu_array)求出数组占用的总空间大小 //通过sizeof(*menu_array)求出数组中的每一个元素的大小 static { "T02LayerSprite.h", "T03LayerZorder.h", "T04ColorLayer.h", "T05Coordinate.h", "T06BatchNode.h", "T07Schedule.h", "T08Touch.h", "T09Memory.h", "T10Label.h" }; CCScene * { CCScene * TMenu * scene->addChild(layer); return } bool { CCLayer::init(); menu = //通过以下的方式实现将菜单项加入到menu中 for (int { CCMenuItem * this, menu_selector(TMenu::menuCallback)); menu->addChild(item); } //设置菜单的显示方向为垂直方向 menu->alignItemsVertically(); addChild(menu); CCArray * array = CCObject * int CCARRAY_FOREACH(array, { CCMenuItem * item->setTag(i i++; } CCMenuItem * closeItem->setTarget(this, CCMenu * menu2->setPosition(CCPointZero); closeItem->setPosition(ccp(winSize.width winSize.height addChild(menu2); //设置触摸事件,为可touch setTouchEnabled(true); setTouchMode(kCCTouchesOneByOne); return } //当点击到菜单之后跳转到指定的CCScene中去 void { CCMenuItem * CCScene * switch (item->getTag() { case 1: pScene = break; case 2: pScene = break; case 3: pScene = break; case 4: pScene = break; case 5: pScene = break; case 6: pScene = break; case 7: pScene = break; case 8: pScene = break; case 9: pScene = break; } if (pScene { //通过CCDirector的sharedDirector来实现场景的切换 CCDirector::sharedDirector()->replaceScene(pScene); } } //当点击关闭的时候游戏退出 void { exit(0); } bool { return } void CCRect CCMenuItem * CCMenuItem * CCPoint CCPoint //当中Delta的坐标表示的是開始坐标的减去最后坐标的差值 if (rcWin.containsPoint(firstInWorld) return; if (rcWin.containsPoint(lastInWorld) return; menu->setPositionY(menu->getPositionY() } |
执行结果: |
版权声明:本文博客原创文章,博客,未经同意,不得转载。