标签:
cc.MenuItem.create(callback, target) |
创建一个空的菜单项,参数说明:
callback 回调函数,用于响应菜单
target 标记项
ctor(callback, target) |
构造函数
initWithCallback(callback, target) |
初始化一个带回调的菜单项
返回 boolean
isEnabled() |
返回菜单是否有效
返回 boolean
isOpacityModifyRGB() setOpacityModifyRGB(value) |
只用于jsb
isSelected() |
返回菜单是否被选中
返回 boolean
rect() |
返回菜单大小(cc.Rect)
selected() |
设置菜单选中属性,等同setIsSelected(true)
unselected() |
等同setIsSelected(true)
setCallback(callback, target) |
设置菜单回调
setEnabled(enable) |
设置菜单有效
setTarget(selector, rec) |
设置菜单选择器
一. cc.MenuItemLabel
var menuitemLabel = new cc.MenuItemLabel(label,selector,target); cc.MenuItemAtlasFont.create(value, charMapFile, itemWidth, itemHeight, startCharMap, callback, target) // Example var item = cc.MenuItemAtlasFont.create( ‘text to display‘ , ‘font.fnt‘ , 12, 32, ‘ ‘ ) //OR var item = cc.MenuItemAtlasFont.create( ‘text to display‘ , ‘font.fnt‘ , 12, 32, ‘ ‘ , game.run, game) cc.MenuItemFont(value, callback, target) cc.MenuItemFont.fontName() //getFontName() |
获取菜单字体名称
cc.MenuItemFont.fontSize() //getFontSize() |
获取菜单字体大小
initWithString(value, callback, target) |
初始化菜单
cc.MenuItemFont.setFontName(name) |
设置字体
cc.MenuItemFont.setFontSize(fontSize) |
设置大小
// Example var item = cc.MenuItemFont.create( "Game start" , ‘start‘ , Game) //创建一个"Game start"菜单, 点击菜单, 运行Game.start() var item = cc.MenuItemFont.create( "Game start" , game.start, Game) //同上 var item = cc.MenuItemFont.create( "i do nothing" ) //创建一个文本菜单,不做任何动作 //还可以设置菜单字体和大小 cc.MenuItemFont.setFontName( ‘my Fancy Font‘ ); cc.MenuItemFont.setFontSize(62); |
二 cc.MenuItemSprite
cc.MenuItemSprite.create(normalSprite, selectedSprite, three, four, five) var item = new cc.MenuItemSprite(normalImage) //使用sprite创建一个空menu,无响应函数 var item = new cc.MenuItemSprite(normalImage, selectedImage) //创建一个空menu,点击无反应 var item = new cc.MenuItemSprite(normalImage, SelectedImage, disabledImage) //效果同上, 但会切换到disableImage var item = new cc.MenuItemSprite(normalImage, SelectedImage, ‘callback‘ , targetNode) //创建菜单,回调函数 getNode.callback() var item = new cc.MenuItemSprite(normalImage, SelectedImage, disabledImage, targetNode.callback, targetNode) //效果同上, but with disabled image, and passing in callback function |
cc.MenuItemImage.create(normalImage, selectedImage, three, four, five) // Example //create a dom menu item with normal and selected state, when clicked it will run the run function from gameScene object var item = cc.MenuItemImage.create( ‘normal.png‘ , ‘selected.png‘ , ‘run‘ , gameScene) //same as above, but pass in the actual function and disabled image var item = cc.MenuItemImage.create( ‘normal.png‘ , ‘selected.png‘ , ‘disabled.png‘ , gameScene.run, gameScene) |
cc.MenuItemToggle() // Example //create a toggle item with 2 menu items (which you can then toggle between them later) var toggler = new cc.MenuItemToggle( cc.MenuItemFont.create( "On" ), cc.MenuItemFont.create( "Off" ), this .callback, this ) //Note: the first param is the target, the second is the callback function, afterwards, you can pass in any number of menuitems //if you pass only 1 variable, then it must be a cc.MenuItem var notYetToggler = new cc.MenuItemToggle(cc.MenuItemFont.create( "On" )); //it is useless right now, until you add more stuff to it notYetToggler.addSubItem(cc.MenuItemFont.create( "Off" )); //this is useful for constructing a toggler without a callback function (you wish to control the behavior from somewhere else) |
具体示例:Cocos2d-js开发小技巧(1)
标签:
原文地址:http://my.oschina.net/soarwilldo/blog/406002