首页 > 代码库 > Cocos2d-x学习笔记(七)菜单
Cocos2d-x学习笔记(七)菜单
文本菜单示例:
#include "HelloWorldScene.h"USING_NS_CC;Scene* HelloWorld::createScene(){ auto scene = Scene::create(); auto layer = HelloWorld::create(); scene->addChild(layer); return scene;}bool HelloWorld::init(){ if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); Sprite *bg = Sprite::create("bg.jpg"); bg->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2)); this->addChild(bg); MenuItemFont::setFontName("Times New Roman"); MenuItemFont::setFontSize(80); MenuItemFont *item1 = MenuItemFont::create("Start", CC_CALLBACK_1(HelloWorld::menuItem1Callback, this));
MenuItemAtlasFont *item2 = MenuItemAtlasFont::create("Help", "fonts/tuffy_bold_italic-charmap.png",48, 65 ,‘ ‘, CC_CALLBACK_1(HelloWorld::menuItem2Callback, this));
Menu *mn = Menu::create(item1, item2, NULL); mn->alignItemsVertically(); this->addChild(mn); return true;}void HelloWorld::menuItem1Callback(cocos2d::Ref *pSender){ MenuItem *item = (MenuItem*)pSender; log("Touch Start Menu Item %p", item);}void HelloWorld::menuItem2Callback(cocos2d::Ref *pSender){ MenuItem *item = (MenuItem*)pSender; log("Touch Help Menu Item %p", item);}
运行效果:
图1 文本菜单示例
Cocos2d-x学习笔记(七)菜单
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。