group.inputEnableChildren = true;
for (var i = 0; i < 10; i++) {
var sprite = group.create(64 + (64 * i), 200, 'beball');
sprite.name = 'child' + i;
sprite.events.onInputDown.add(clickedSprite, this);
}
function clickedSprite(sprite) {
console.log(sprite.name);
}
输出的永远是child9
经过简单分析和对比。发现了问题
var width = displayObject.texture.frame.width / displayObject.texture.baseTexture.resolution; var height = displayObject.texture.frame.height / displayObject.texture.baseTexture.resolution; var x1 = -width * displayObject.anchor.x; if (this._localPoint.x >= x1 && this._localPoint.x < x1 + width){ var y1 = -height * displayObject.anchor.y; if (this._localPoint.y >= y1 && this._localPoint.y < y1 + height){ return true; } }
// this._localPoint.x,y始络为0,0
为什么呢?你们慢慢想吧。
先解决问题了再说吧.
hitTest: function (displayObject, pointer, localPoint){
if (!displayObject.worldVisible){
return false;
}
if (pointer.x != pointer.x) {
pointer.x = pointer.clientX;
}
if (pointer.y != pointer.y) {
pointer.y = pointer.y;
}
}
解决!