通过代码创建一个新的节点后,给该节点添加触摸和鼠标事件均不触发,想请教一下为什么会这样,萌新求问
不用foreach看下,改成for循环
node 的 layer 看下是否是 UI_2D?
大佬, 您的代码是这个吧, 请问加了这一行
console.log(node.name+“点击屏幕, 节点值为=>”,node);
这样打印的结果是啥 ?
async createFruit(){
this.fruitList = await common.loadResources("sprite");
let sumIndex=0;
Fruitstructure.fruitList.forEach((fruit, index1) =>{
const node = common.createNode(`fruit${index1}`, this.node);
node.name+="_"+sumIndex;
node.scale = new Vec3(0.9, 0.9,0);
node.on(Node.EventType.MOUSE_DOWN,this.onClick,node,true);
node.on(Node.EventType.TOUCH_START, this.onClick,node);
console.log(node.name+"点击屏幕, 节点值为=>",node);
const sprile = node.addcomporent(sprile);
sprite.spriteFrame = this.fruitList.find(pic => pic.name === `fruit${fruit.type}`);
console.log('node', node);
sumIndex++;
});
}
