1.场景加载
cc.director.loadScene('场景名称');//场景跳转
cc.director.preloadScene('场景名称');//预加载场景
cc.director.getScene();//获取当前场景
2.获取节点
var node = cc.find("Canvas/bg");//通过访问路径来获取节点
var a = this.node.getChildByName('name');//通过名字获取子节点
node.getComponent(cc.Label).string = 'abc';//获取节点上的组件值
var a = cc.find("Canvas/bg").getComponent(cc.Sprite);//通过访问路径来获取节点,及获取该节点的指定组件
this.node .getChildByName('节点名称').getComponent(cc.Label)//通过节点名获取子节点,获取该节点指定组件
var a = this.node;//获取当前脚本所在的节点
var a = this.node.parent;//获取父节点
var a = this.node.getChildByTag(1001);//通过标签获取子节点
var a = cc.find("bg/score",this.node);//通过指定节点下的路径获取节点
var a = this.node.children;//获取所有子节点
var a = this.node.childrenCount;//获取子节点数量
var a = cc.director.getScene();//获取场景主节点
var a = cc.instantiate(node);//克隆节点
this.node.parent = cc.find('Canvas');//绑定父节点
this.node.addChild(nodeName,zIndex,tag);//添加子节点,可设置层级和标签
this.node.removeChild(nodeName);//通过名字移除子节点
this.node.removeChildByTag (nodeTag);//通过标签移除子节点
this.node.destroy();//销毁节点
this.node.isValid;//判定节点是否可用
this.node.removeChild(newNode);//移除节点中指定的子节点
this.node.removeChildByTag(1001);//通过标签移除节点中指定的子节点
this.node.removeAllChildren();//移除所有子节点
this.node.destroyAllChildren();//销毁所有子节点
this.node.cleanup();//停止所有正在播放的动作和计时器
var sprites = this.node.getComponentsInChildren(cc.Label);//递归查找自身及所有子节点中指定类型的组件
3.获取节点位置,设置节点
var a = node.getPositionX();或 getPositionY() //获取节点的X轴或Y轴坐标
var a = node.getScaleX(); 或getScaleY() //获取节点的X轴或Y轴缩放比例
node.x = 100;//设置节点x轴坐标
node.y = 100;//设置节点y轴坐标
node.setPo
cocos creator 常用函数汇总
最新推荐文章于 2023-10-09 23:58:17 发布