我有一个if语句,它通过根据索引位置从数组中读取字符串来创建文本对象。
if (ifpn > 12){
list = game.add.text(game.world.centerX+850, yfp, text, style);
game.physics.arcade.enable(list);
list.inputEnabled = true;
list.input.enableDrag();
list.events.onDragStart.add(startList, this);
list.events.onDragStop.add(stopList, this);
}
在该语句中,我有一个侦听器事件,触发其范围外的自定义函数。
function startList(selected){
var posx = game.input.mousePointer.x;
var posy = game.input.mousePointer.y;
if (canc > 0){
console.log('too many');
}
else {
if (list.position.y > posy){
list.position.y = list.position.y-40; //doesn't work as expected
}
else{
console.log('too tall');
}
game.world.remove(selected);
}
};
此功能的作用是当用户开始拖动列表对象时,它获取鼠标的y位置,并从下面的任何其他列表对象的高度减去40px鼠标点击点。
但是因为 list 被定义为全局变量list = null;
,然后在范围外给出一个值,该语句仅影响由于闭包而最后创建的 list 对象。
如何更改所有 list 对象的高度属性而不仅仅是最后创建的对象?
请更正我在代码中看到的任何错误或问题的解释。
由于