在组件中初始化函数后,A-Frame 不删除属性。
A-Frame not removing attribute after function being initialized in a component.
我正在尝试添加一个单击处理程序,它会在单击单独的实体时切换实体的灯光属性。但是,当我单击单独的实体时,什么也没有发生,并且我的控制台中没有任何错误。
这是我的组件:
AFRAME.registerComponent("lightsOut", {
schema: {
target : { type : "selector"}
},
init: function(){
this.el.addEventListener("click",function(){
this.data.target.removeAttribute("light");
}.bind(this));
}
})
这是两个实体:
<a-entity id="streetLamp"
obj-model="obj:./models/streetlamp/StreetLamp.obj;mtl:./models/streetlamp/StreetLamp.mtl"
material="color:black"
scale="0.3 0.6 0.5"
position="-7.138 -1.499 -11.711"
lightsOut="target:#streetLight">
</a-entity>
<a-entity id="streetLight"
position="-4.961 6.205 -11.962"
rotation="-67.208 -112.987 87.548"
scale="0.657 0.612 0.718"
light="distance:15;decay:2;intensity:5a;angle:90;color:#ff8000;groundColor:#ffffff;penumbra:0.5;castShadow:true;type:point"
></a-entity>
当我点击 streetLamp 时,我想删除或隐藏 streetLight。我正在使用光标控件。
组件名中不能有大写字母,a-frame会尝试把它改成小写,(...)最后还是不行。
尝试将其命名为 lightsout
或 lights_out
。单击时放入 console.log(),以确保其正常工作。
此外,您需要使用 raycaster.refreshObjects()
手动刷新 raycaster,这是一个错误,已在 december 2017 主版本中修复。
我正在尝试添加一个单击处理程序,它会在单击单独的实体时切换实体的灯光属性。但是,当我单击单独的实体时,什么也没有发生,并且我的控制台中没有任何错误。
这是我的组件:
AFRAME.registerComponent("lightsOut", {
schema: {
target : { type : "selector"}
},
init: function(){
this.el.addEventListener("click",function(){
this.data.target.removeAttribute("light");
}.bind(this));
}
})
这是两个实体:
<a-entity id="streetLamp"
obj-model="obj:./models/streetlamp/StreetLamp.obj;mtl:./models/streetlamp/StreetLamp.mtl"
material="color:black"
scale="0.3 0.6 0.5"
position="-7.138 -1.499 -11.711"
lightsOut="target:#streetLight">
</a-entity>
<a-entity id="streetLight"
position="-4.961 6.205 -11.962"
rotation="-67.208 -112.987 87.548"
scale="0.657 0.612 0.718"
light="distance:15;decay:2;intensity:5a;angle:90;color:#ff8000;groundColor:#ffffff;penumbra:0.5;castShadow:true;type:point"
></a-entity>
当我点击 streetLamp 时,我想删除或隐藏 streetLight。我正在使用光标控件。
组件名中不能有大写字母,a-frame会尝试把它改成小写,(...)最后还是不行。
尝试将其命名为 lightsout
或 lights_out
。单击时放入 console.log(),以确保其正常工作。
此外,您需要使用 raycaster.refreshObjects()
手动刷新 raycaster,这是一个错误,已在 december 2017 主版本中修复。