第一步:导入类
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("梅头发");
}
本文介绍了一个简单的游戏开发示例,展示了如何通过导入自定义的玩家类并在场景中创建实例节点来实现游戏对象的实例化过程。
1万+

被折叠的 条评论
为什么被折叠?



