【问题标题】:How to detect which Sprite got clicked on如何检测点击了哪个 Sprite
【发布时间】:2022-01-26 16:28:30
【问题描述】:

我试图弄清楚如何知道点击了哪个 Sprite

   var current_dots:Array<Sprite>= [];
   for(i in 0...4){
      var page = new Sprite(); 
      current_dots.push(page);
      page.on('pointerdown', dot_click);
      this.addChild(page);
    }
   function dot_click(){
      trace("CLICKED");
    }

因为每个精灵都是在 for 循环中声明的,所以我不确定如何识别哪个精灵被点击了

【问题讨论】:

    标签: javascript onclick pixi.js


    【解决方案1】:

    我想办法做到这一点

      function dot_click(e:InteractionEvent){
        for( i in 0...current_dots.length){
          if(current_dots[i] == e.currentTarget) {
             trace("Clicked")
          }
          
        }
      }
    

    必须传递交互参数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 2016-03-28
      • 1970-01-01
      相关资源
      最近更新 更多