【问题标题】:How to change position of a <a-entitiy> onclick如何更改 <an-entity> onclick 的位置
【发布时间】:2019-12-05 16:04:58
【问题描述】:

如果光标位于对象上方并且单击鼠标,我会尝试让点击时消失,如果在新位置重生则让。

我使用 aframe-event-set-component (https://www.npmjs.com/package/aframe-event-set-component) 来实现这一点,但我无法传递新的随机生成位置。

希望有人能帮帮我:)

我尝试使用字符串插值和数据绑定传递新的位置坐标,但没有成功。

<a-entity>
<a-gltf-model 
  src="../../assets/models/CoinBlock.gltf" 
  position="1.5 2 -0.5" 
  rotation="15 -50 0" 
  radius="1.25"
  scale="0.002 0.002 0.002"
  event-set__down="_event: mousedown; position: -1 0.5 -0.5; rotation: -45 45 0"
</a-gltf-model>

【问题讨论】:

    标签: angular aframe


    【解决方案1】:

    使用event-set__enter 代替event-set__down 并使用click 代替mousedown。您还可以通过在rotation: -45 45 0; 之后添加visible: false 来消除您的实体

    <a-entity>
        <a-gltf-model 
            src="../../assets/models/CoinBlock.gltf" 
            position="1.5 2 -0.5" 
            rotation="15 -50 0" 
            radius="1.25"
            scale="0.002 0.002 0.002"
            event-set__enter="_event: click; position -1 0.5 -0.5; rotation: -45 45 0"
        </a-gltf-model>
    

    【讨论】:

      【解决方案2】:

      由于您使用的是 Angular,我建议您通过其模板操作框架。

      使用 Angular 模板:

      <ng-container *ngIf="show">
          <a-gltf-model 
            src="../../assets/models/CoinBlock.gltf" 
            [attr.position]="position" 
            rotation="15 -50 0" 
            radius="1.25"
            scale="0.002 0.002 0.002"
            (click)="despawn()"
          </a-gltf-model>
      </ng-container>
      

      显示和隐藏:

      public show: boolean = true;
      
      despawn() {
          this.show = false;
      }
      

      根据一些新的点击事件在新位置重生:

      respawn() {
          this.position = '0 0 0'; // your new position
          this.show = true;
      }
      

      【讨论】:

        猜你喜欢
        • 2017-06-21
        • 1970-01-01
        • 1970-01-01
        • 2018-09-17
        • 1970-01-01
        • 1970-01-01
        • 2016-11-06
        • 2014-08-25
        • 2011-04-07
        相关资源
        最近更新 更多