精灵
var sprite = new cc.Sprite(res.); sprite.setPosition(,); this.addChild(sprite);
文本标签
var label = new cc.LabelTTF("","",30);
label.x = ;
label.y = ;
this.addChild(label);
数字标签
var atlas = new cc.LabelAtlas("",res.,"");
atlas.x = ;
atlas.y = ;
this.addChild(atlas);
图片菜单项
var item = new cc.MenuItemImage(res.,this.menuItemCallback,this);
item.x = ;
item.y = ;
menuItemCallback:function(sender){
cc.log("menuItemStartCallback")
},
菜单
var menu = new cc.Menu(item); menu.x = ; menu.y = ; this.addChild(menu);
坐标转换
{cc.Point} convertToNodeSpace(worldPoint);//将世界坐标转换为模型坐标。
{cc.Point} convertToNodeSpaceAR(worldPoint);//将世界坐标转换为模型坐标。AR表示相对于锚点。
{cc.Point} convertTouchToNodeSpace(touch);//将世界坐标中触摸点转换为模型坐标。
{cc.Point} convertTouchToNodeSpaceAR(touch);//将世界坐标中触摸点转换为模型坐标。AR表示相对于锚点。
{cc.Point} convertToWorldspace(nodePoint);//将模型坐标转换为世界坐标。
{cc.Point} convertToWorldspaceAR(nodePoint);//将模型坐标转换为世界坐标。AR表示相对于锚点。
ccs导出文件读取
var root = ccs.load(res.MainScene_json);
var mainscene = root.node;
this.addChild(mainscene);
var button = ccui.helper.seekWidgetByName(mainscene,"Button");
button.addTouchEventListener(this.touchEvent,this);
touchEvent:function(sender,type){
switch (type) {
case ccui.Widget.TOUCH_BEGAN:
this.label.setString("Touch Down");
break;
case ccui.Widget.TOUCH_MOVED:
this.label.setString("Touch Move");
break;
case ccui.Widget.TOUCH_ENDED:
this.label.setString("Touch Up");
break;
case ccui.Widget.TOUCH_CANCELED:
this.label.setString("Touch Cancelled");
break;
default:
break;
}
},
单例
var Singeleton = (function(){
var instance;
function init (){
return {
propery:"propery",func:function(){
console.log(this.propery);
}
};
};
return {
getInstance:function(){
if(!instance){
instance = init();
}
return instance;
}
};
})();
Singeleton.getInstance().func();
function outObj(obj){
cc.log("object detail---");
for (prop in obj) {
cc.log(prop + ":" +obj[prop]);
}
}