创建颜色层 (LayerColor)API :
var LayerColor = new cc.LayerColor(cc.color(0,0,0,120), cc.winSize.width, cc.winSize.height);
scene.addChild(LayerColor);
- 1
- 2
文本描边 :
label.enableOutline(cc.color.BLACK, 2);
//cc.color.BLACK 是 颜色 也可以 cc.color(100,100,100,255);
//2 是描边宽度
- 1
- 2
- 3
自定义事件 :
替换图片API :
sprite.initWithFile(url);
- 1
实例 :
node.initWithFile("res/normalBox.png");
- 1
使用plist显示图片( 精灵缓存 SpriteFrameCache ) :
cocos2d - JS 精灵帧缓存 ( SpriteFrameCache ) - 链接
纹理缓存 :
将图片添加到内存中 , 返回纹理创建对象 .
var textrue = cc.textureCache.addImage(res.bg_png);
var node = new cc.Sprite(textrue);
//或者
var node = new cc.Sprite(res.bg_png);
- 1
- 2
- 3
- 4
- 5
- 6
获取当前场景 API :
var currentScene = cc.director.getRunningScene();
- 1
LayerColor :
var layer = new cc.LayerColor(cc.color(0,0,0,155),cc.winSize.width + 200, cc.winSize.height + 200);
- 1
BMFont(根据字体显示字符串) :
var BMFont = new cc.LabelBMFont("test" , res.font);
BMFont.setPosition(300,300);
this.addChild(BMFont);
- 1
- 2
- 3
输入框 EditBox :
var sp = new cc.Scale9Sprite("res/edibg.jpg");
var account = new cc.EditBox(cc.size(459, 45), sp);
account.setFontColor(cc.color.BLACK);
account.setPosition(cc.winSize.width/2, cc.winSize.height/2);
this.addChild(account);
- 1
- 2
- 3
- 4
- 5
- 6
创建按钮 和 菜单(Menu) :
var startBtn = new cc.MenuItemImage(res.Btn, res.Btn, this.menuCallBack, this);
- 1
//添加多个按钮 方法和上面一样
var menu = new cc.Menu(startBtn, exitBtn, settingBtn);
menu.setPosition(100, 100);
this.addChild(menu);
- 1
- 2
- 3
- 4
单个按钮可以直接使用下面的代码
var TestBtn = new cc.Menu(new cc.MenuItemImage(res.Btn, res.Btn, this.callback, this));
TestBtn.setPosition(100, 100);
this.addChild(TestBtn);
- 1
- 2
- 3
callback: function(sender){
cc.log("回调函数");
},
- 1
- 2
- 3
- 设置正常和选中显示效果 :
callback: function(sender){
sender.setNormalSpriteFrame(res.soundBtn3);
sender.setSelectedSpriteFrame(res.soundBtn4);
},
- 1
- 2
- 3
- 4
- 5
文字 ( Label ) :
var label = new cc.LabelTTF("test", "Microsoft YaHei", 42);
- 1
设置层级 :
node.setLocalZOrder(99);
- 1
特效转场 :
cc.director.runScene(new cc.TransitionFade(time, scene));
- 1
坐标转换 :
本地坐标转为世界坐标 :
var toWorldPos = nodeParent.convertToWorldSpace(node.getPosition());
//受锚点影响
var toWorldPos = nodeParent.convertToWorldSpaceAR(node.getPosition());
- 1
- 2
- 3
- 4
世界坐标转化为本地坐标 :
var toNodePos = node_A.convertToNodeSpace(node_B);
//受锚点影响
var toNodePos = node_A.convertToNodeSpaceAR(node_B);
- 1
- 2
- 3
- 4
设置高清 :
cc.view.enableRetina(true);
- 1
查看引擎版本 :
cc.ENGINE_VERSION
- 1