guansss / pixi-live2d-display

A PixiJS plugin to display Live2D models of any kind.
https://guansss.github.io/pixi-live2d-display/
MIT License
810 stars 123 forks source link

取消自动交互后,model.on('pointerdown')或‘hit’事件无法触发 #153

Closed Yorenzz closed 1 month ago

Yorenzz commented 1 month ago

翻了好久,不知道是由哪里控制的0.0

liyao1520 commented 1 month ago

翻了好久,不知道是由哪里控制的0.0

  const model = await Live2DModel.from('', { autoInteract: false })
Yorenzz commented 1 month ago

翻了好久,不知道是由哪里控制的0.0

  const model = await Live2DModel.from('', { autoInteract: false })

感谢感谢

Yorenzz commented 1 month ago
const model = await Live2DModel.from(modelJson, { motionPreload: MotionPreloadStrategy.NONE, autoInteract: false })
  document.getElementById(canvasID).addEventListener('pointerdown', (event) => model.tap(event.clientX, event.clientY))

  // 创建模型对象
  const app = new PIXI.Application({
    view: document.getElementById(canvasID),
    autoStart: true,
    resizeTo: window,
    // 透明
    backgroundColor: 0xffffff,
    backgroundAlpha: 0
  })

  // 添加模型到舞台
  app.stage.addChild(model)
  // 模型的缩放
  model.scale.set(0.08)
  // 模型的位置,x,y相较于窗口左上角
  model.x = 0
  // 添加模型状态管理器
  const a = new InternalModel(model)
  model.InternalModel = a
  // 绑定模型点击事件动作
// hit一样
  model.on('pointerdown', (hitAreas) => {
    console.log(11111)
    // hitAreas:模型的一些上下文
    const { x, y } = hitAreas.data.global
    const point = model.hitTest(x, y)
    if (point.includes('Head')) {
      model.motion('TapHead')
    } else if (point.includes('ArtMesh20')) {
      model.motion('Tap')
    }
  })

取消自动交互后,按照文档addEventListener了,但是pointerdown事件没有触发,pointermove事件是正常的