我正在创建一个 10x10 的形状网格并将点击事件附加到每个形状
var g = new Graphics();
for (var x=0; x<10; ++x) {
for (var y=0; y<10; ++y) {
var s = new Shape();
//s.cache(0, 0, self.segmentWidth, self.segmentWidth);
s.graphics.beginFill('rgba(0,0,255,.4)');
s.graphics.drawRect(0, 0, self.segmentWidth, self.segmentWidth);
s.x = x * self.segmentWidth;
s.y = y * self.segmentWidth;
var id = s.x + '_' + s.y;
self.cells[id] = s;
self.stage.addChild(s);
s.addEventListener('click', self.cellClick);
}
}
但是当我调用 self.cellClick 时,目标坐标始终为 0
this.cellClick = function(e) {
var s = e.target;
console.log(s); // x : 0, y : 0
self.cells[s.x + '_' + s.y].alpha = 0.5;
self.update = true;
}
有谁知道为什么会这样?
谢谢