cocos2d-js常用方法一览表
发布时间:2020-12-14 20:45:42 所属栏目:百科 来源:网络整理
导读:精灵 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 = ;atla
精灵
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]); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |