首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Aframe -用于拖动的事件

Aframe -用于拖动的事件
EN

Stack Overflow用户
提问于 2018-02-06 15:33:30
回答 1查看 526关注 0票数 0

我使用的是Aframe-React和Aframe Click Drag component

这工作得很好,我现在正在尝试如何将事件添加到实体中,这样当我的一个实体被拖动时,我可以更新这些计算(这些线是它们之间的弯头连接-我想在拖动项目时更新这些计算)

这些实体稍后会被赋予Click Drag属性,不过我认为最好在这里添加侦听器。

该库提供了一个事件示例

https://github.com/jesstelford/aframe-click-drag-component/blob/master/examples/events/index.html

并将这些事件注册为此类事件

代码语言:javascript
复制
  event-set__1="_event: dragstart; material.opacity: 0.2" 

但是,我似乎不知道如何在这个类中使调用成为一个函数,

也就是说,类似于

event-set__1="_event: dragstart“应调用dragStart()函数。

有关于如何做到这一点的线索吗?

代码语言:javascript
复制
const scalar = 0.2
const offsetX = 4
const offsetY = 4.5

config.scale = {x: scalar, y: scalar, z: scalar}

if (editingHotspot.shape) {

  buttonConfig.position = {
    x: config.position.x + offsetX,
    y: config.position.y + offsetY,
    z: config.position.z,
  }

  const shapeTop = {
    x: config.position.x,
    y: config.position.y + 1.9,
    z: config.position.z,
  }

  const buttonEdge = {
    x: buttonConfig.position.x - geometry.width * 0.5 * scalar,
    y: buttonConfig.position.y,
    z: buttonConfig.position.z,
  }

  const join = {
    x: shapeTop.x,
    y: buttonEdge.y,
    z: (shapeTop.z + buttonEdge.z) / 2,
  }

  lineX = {
    lineWidth: 10,
    path: AFRAME.utils.coordinates.stringify(buttonEdge) + ',' + AFRAME.utils.coordinates.stringify(join),
    color: '#fff',
  }
  lineY = {
    lineWidth: 10,
    path: AFRAME.utils.coordinates.stringify(shapeTop) + ',' + AFRAME.utils.coordinates.stringify(join),
    color: '#fff',
      }
    }
  }

  let dragStart = (e) => {
    console.log(e)
  }

  let params = {
    'hotspots-button': 'text:' + (button.label != null ? button.label : '') + ';' + 'icon:' + (button.icon != null ? button.icon.preview : '') + ';',
    draw: 'width:256; height:' + (button.icon != null ? '256' : '128') + ';',
  }

  return (
    <Entity className='hotspot button' {...params} >
      <Entity
        className='hotspot button'
        primitive='a-image'
        look-at='[camera]'
        {...{geometry}}
        scale={config.scale}
        position={editingHotspot.shape ? buttonConfig.position : config.position}
      />
      {
        editingHotspot.shape &&
          <Entity>
            <Shape config={config} editingHotspot={editingHotspot}/>
            <Entity meshline={lineX}/>
            <Entity meshline={lineY}/>
          </Entity>
      }

    </Entity>
  )
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-06 17:27:24

据我所知,Kevin的event-set component设置了目标/自我属性(他的非最小化dist的第121行),这意味着它不能调用方法(除了update,只要属性发生变化就会调用它)

我会在我的组件中创建自己的监听器,或者仅仅是一个监听器->调用者

代码语言:javascript
复制
AFRAME.registerComponent("listener", {
  init: function() {
     this.el.addEventListener("startDrag", (e)=> {
        // call your function here.
        // if you want to call another component's function, you can do
        // this.el.components.componentWithMethod.method()
     }
  }
}

就像this一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48637707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档