cocos2d-x 3.0菜单的使用
2016-04-08 13:11
423 查看
菜单中又包含了菜单项,菜单项类是MenuItem,每个菜单项都有三个基本状态:正常、选中、禁止。
菜单分类是按照菜单项进行分类的。
MenuItem的子类有
MenuItemLabel(文本)
MenuItemSprite(精灵)
MenuItemToggle(开关)
其中MenuItemLabel类有两个子类MenuItemAtlasFont和MenuItemFont;
MenuItemSprite类是精灵菜单,它的子类是MenuItemImage,是图片菜单;
MenuItemToggle是开关菜单。
1、文本菜单类MenuItemLabel,它的创建函数create定义如下:
static MenuItemLabel * create(Node*label, const ccMenuCallback& callback);
static MenuItemLabel* create(Node *label);
2、MenuItemFont是继承MenuItemLabel的,所以它有MenuItemFont的一些特性,它的创建函数create如下定义:
static MenuItemFont * create(const std::string& value = "");
static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback);
3、MenuItemAtlasFont是继承MenuItemLabel的,所以它有MenuItemFont的一些特性,它是基于图片集的文本菜单项,它的创建函数create如下定义:
static MenuItemAtlasFont* create(
const std::string& value,
const std::string& charMapFile,
int itemWidth, int itemHeight,
char startCharMap);
static MenuItemAtlasFont* create(
const std::string& value,
const std::string& charMapFile,
int itemWidth, int itemHeight,
char startCharMap,
const ccMenuCallback& callback);
第一个参数是要显示的文本,第二个是图片集文件,第三、四个是要截取的文字在图片的宽和高,第五个是图片集文件的开始字符
4、精灵菜单项类的其中一个创建函数create定义如下:
static MenuItemSprite * create(
Node* normalSprite,
Node* selectedSprite,
const ccMenuCallback& callback);
参数一是菜单项正常显示的精灵,参数二是选择菜单项显示的精灵。
使用MenuItemSprite 比较麻烦,在创建MenuItemSprite 之前要先创建三种不同状态时的精灵(normalSprite、selectorSp rite、disabledSprite)。MenuItemSprite 还有一些create函数,在这些create函数中可以省略disabledSprite参数。
5、如果精灵是由图片构成的可以使用MenuIte mImage实现与精灵菜单同样的效果。它的其中一个创建函数create定义如下:
static MenuItemImage* create(
const std::string&normalImage,
const std::string&selectedImage,
const ccMenuCallback& callback);
6、开关菜单的菜单项类是MenuItemToggle,它是一种可以进行两种状态切换的菜单项。
它可以通过下面的函数创建:
static MenuItemToggle * createWithCallback(
const ccMenuCallback& callback,
const Vector<MenuItem*>& menuItems);
参数二是进行切换的菜单项
从第二个参数开始都是MenuItem类的实例对象,他们是开关菜单显示的菜单项,他们可以使文本、图片和精灵类型的菜单项。
菜单分类是按照菜单项进行分类的。
MenuItem的子类有
MenuItemLabel(文本)
MenuItemSprite(精灵)
MenuItemToggle(开关)
其中MenuItemLabel类有两个子类MenuItemAtlasFont和MenuItemFont;
MenuItemSprite类是精灵菜单,它的子类是MenuItemImage,是图片菜单;
MenuItemToggle是开关菜单。
1、文本菜单类MenuItemLabel,它的创建函数create定义如下:
static MenuItemLabel * create(Node*label, const ccMenuCallback& callback);
static MenuItemLabel* create(Node *label);
2、MenuItemFont是继承MenuItemLabel的,所以它有MenuItemFont的一些特性,它的创建函数create如下定义:
static MenuItemFont * create(const std::string& value = "");
static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback);
3、MenuItemAtlasFont是继承MenuItemLabel的,所以它有MenuItemFont的一些特性,它是基于图片集的文本菜单项,它的创建函数create如下定义:
static MenuItemAtlasFont* create(
const std::string& value,
const std::string& charMapFile,
int itemWidth, int itemHeight,
char startCharMap);
static MenuItemAtlasFont* create(
const std::string& value,
const std::string& charMapFile,
int itemWidth, int itemHeight,
char startCharMap,
const ccMenuCallback& callback);
第一个参数是要显示的文本,第二个是图片集文件,第三、四个是要截取的文字在图片的宽和高,第五个是图片集文件的开始字符
4、精灵菜单项类的其中一个创建函数create定义如下:
static MenuItemSprite * create(
Node* normalSprite,
Node* selectedSprite,
const ccMenuCallback& callback);
参数一是菜单项正常显示的精灵,参数二是选择菜单项显示的精灵。
使用MenuItemSprite 比较麻烦,在创建MenuItemSprite 之前要先创建三种不同状态时的精灵(normalSprite、selectorSp rite、disabledSprite)。MenuItemSprite 还有一些create函数,在这些create函数中可以省略disabledSprite参数。
5、如果精灵是由图片构成的可以使用MenuIte mImage实现与精灵菜单同样的效果。它的其中一个创建函数create定义如下:
static MenuItemImage* create(
const std::string&normalImage,
const std::string&selectedImage,
const ccMenuCallback& callback);
6、开关菜单的菜单项类是MenuItemToggle,它是一种可以进行两种状态切换的菜单项。
它可以通过下面的函数创建:
static MenuItemToggle * createWithCallback(
const ccMenuCallback& callback,
const Vector<MenuItem*>& menuItems);
参数二是进行切换的菜单项
从第二个参数开始都是MenuItem类的实例对象,他们是开关菜单显示的菜单项,他们可以使文本、图片和精灵类型的菜单项。
相关文章推荐
- cocos2d-x 文本标签的用法
- cocos2dx 游戏当中的战争迷雾
- cocos在win平台exe无法使用 UserDefault 解决方法
- Cocos2d-x:TexturePacker的使用
- [cocos2dx笔记017]cocos2dx 2.2.6 lua的类型转换
- [cocos2dx笔记016]cocos2dx 3.2 的UserDefault
- 【步兵 经验篇】关于脚本语言的优势
- Cocos2d-x 3.10 开发环境的配置
- cocos2d-x C++ 利用C++11新特性+runAction RepeatForever Sequence DelayTime做一个持续循环函数 每秒更新 5次后停止
- ocos2dx常见的46种动作+22种特效详解
- cocos2dx--CCSprite,CCSpriteFrame,CCTexture,CCSpriteBatchNode
- cocos2d-js常用命令
- Cocos2d-x学习笔记(10)(CCMenu菜单)
- 游戏底层逻辑,运动&&寻路(一)
- Cocos2d-x多语言支持解决方式
- cocos2dx--纹理平铺
- Cocos2d-x 场景中的生命周期函数?
- Cocos2dx 3.0 过渡篇(二十九)globalZOrder()与localZOrder()
- Cocos2d-JS 笔记(SUN)
- cocos2dx3.2 画图方法小修改之 C++ final学习