game.js
cc.Class({
extends: cc.Component,
properties: {
//老鼠的预设体数组
mousePrefab: [cc.Prefab],
//老鼠的位置数组
pointmouse:[cc.Vec2],
//锤子的的预设体 default:系统默认值 cc.Prefab预制文件实例
chuziPrefab:{
default:null,
type:cc.Prefab
}
},
spawnNewMouse: function() {
//获取0-2的数
var num=Math.floor(Math.random()*3)
//cc.instantiate来进行初始化(可以理解为实例化创建)
var newMouse=cc.instantiate(this.mousePrefab[num]);
// 将新增的节点添加到 Canvas 节点下面
this.node.addChild(newMouse);
this.mouse=newMouse;
// 为mouse设置一个随机位置
var num1=Math.floor(Math.random()*9)
newMouse.setPosition(this.pointmouse[num1]);
this.mousepoint=newMouse.getPosition()