第一步:导入类
1.这是MyGame类,导入Player类
var mg={};
mg.player=require("Player");
mg.Height=100;
module.exports=mg;
第二步:创建对象,在MyScene中
//需要在cc.class之前导入
var MyGame=require("MyGame");
start () {
//调用该函数
this.createNode();
},
createNode:function(){
var otherNode=new cc.Node("otherNode");
this.Player=otherNode.addComponent(MyGame.player);
otherNode.setParent=this.Node;
//克隆
var clone=cc.instantiate(otherNode);
this.node.addChild(clone);
cc.log("梅头发");
}