在练习碰撞组件的时候,希望生成不同图片带有不同的碰撞框,官方案例上有随机生成图片的案例,我修改了一下,我的想法是将带有不同碰撞框的不同图片作为节点放在预制资源里,然后预制资源随机生成一个节点
var Helpers = require(‘Helpers’);
cc.Class({
extends: cc.Component,
properties: {
spriteList: {
default: [],
type: [cc.Node]
}
},
// use this for initialization
onLoad: function () {
var randomIdx = Helpers.getRandomInt(0, this.spriteList.length);
var sprite = this.spriteList[randomIdx];
}
});
为什么不能够随机生成一个节点。