phaser的小遊戲的onInputDown問題

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);
}this

function clickedSprite(sprite) {spa

  console.log(sprite.name);code

}blog

輸出的永遠是child9input

通過簡單分析和對比。發現了問題it

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){io

  if (!displayObject.worldVisible){
    return false;
  }console

  if (pointer.x != pointer.x) {
    pointer.x = pointer.clientX;
  }
  if (pointer.y != pointer.y) {
    pointer.y = pointer.y;
  }event

}function

 

解決!

相關文章
相關標籤/搜索