galacean/effects-runtime

[Bug] 跟踪的点击块在别的地方也会触发

Closed this issue · 3 comments

🔎 搜索关键词

none

🕗 版本信息

1.14

🖥️ 平台信息

  • iOS
  • Android
  • Web
  • 小程序(支付宝/微信)
  • 微信小游戏
  • macOS
  • Windows
  • Linux
  • Other

💻 Sample Code

image
interact_10交互元素和sprite_7元素绑定,而且一起移动。
但是添加点击事件的时候,sprite_1在移动的时候点击偶尔也会触发

🙂 预期行为

只有点击与10号元素绑定的7号元素时才触发

🙁 实际行为

点击元素1也触发了,但是没有一次点击元素3触发,元素3是静态元素

⏯ Steps to Reproduce

<script setup>
import {onBeforeUnmount, onMounted, ref} from "vue";
import { Player } from '@galacean/effects'
import js1 from '@/assets/ttt/tt1.json'
const cvsRef = ref(null);
let player;
onMounted(() => {
  // 在这里使用cvsRef.value
  player = new Player({
    container: cvsRef.value,
    interactive: true,
    onItemClicked: handleClick,
  })
  js1.images.forEach(v=> {
    v.url = imagesUrlChange(v.url)
    v.webp = imagesUrlChange(v.webp)
  })
  player.loadScene(js1)
})

const handleClick = (item) => {
  console.log(item);
  if (item.id === '10'){
    alert('你干嘛~')
  }
}

const imagesUrlChange = (url) => {
  let baseUrl = import.meta.env.VITE_BASE_PATH;
  return new URL(url.replace('.\/', '..\/assets\/ttt/'), import.meta.url)
}

onBeforeUnmount(() => {
  player.dispose()
})
</script>

<template>
  <div id="cvs" ref="cvsRef" class="w-screen h-screen">

  </div>
</template>

<style scoped>

</style>

其它信息

No response

麻烦提供一下导出产物,方便定位问题

  1. 点击 sprite_1 会触发点击事件是因为sprite_1元素开启了交互属性,并且交互行为是消息通知,如果不需要此元素响应点击关闭即可
  2. 如果需要 sprite_1 和 interact_10 均响应点击,可以在回调里通过 name 判断是哪个元素被点中,同时被点中二者都会响应