zoukankan      html  css  js  c++  java
  • 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);
    }

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

    }

    解决!

     
  • 相关阅读:
    026.MFC_发送消息
    021.MFC_字体和颜色对话框
    020.MFC_文件对话框
    015.MFC_Menu
    qt http get post实现
    openssl error: unrecognized command line option '-m64'
    ModbusTCP协议
    013.MFC_TreeControl
    菱形继承问题以及解决
    ffmpeg
  • 原文地址:https://www.cnblogs.com/honghong87/p/9466553.html
Copyright © 2011-2022 走看看