我正在使用 A-Frame 并尝试生成池多个“云”实体,这些实体一旦激活就会慢慢开始朝特定方向移动,但 tick()
函数似乎并没有被召唤!有没有办法启动它,或者我需要手动管理它?
这是我用来测试 1 个云的设置:
HTML
<a-assets>
<a-mixin id="cloud" cloud></a-mixin>
</a-assets>
<a-entity
cloudmanager
pool="mixin: cloud; size: 1;">
</a-entity>
cloudmanager.js
AFRAME.registerComponent("cloudmanager", {
init: function(){
const cloudEl = this.el.components.pool.requestEntity();
cloudEl.components.cloud.startMoving();
}
});
cloud.js
AFRAME.registerComponent("cloud", {
//LIFECYCLE
//-----------
init: function(){
this.startMoving = this.startMoving.bind(this);
this.moving = false;
// ...and then create the cloud geometry etc etc
},
tick: function(time, deltaTime){
console.log("tick"); //never happens!
if(this.moving) this.move(deltaTime);
},
//UTILS
//-----------
startMoving: function(){
console.log("starting to move!"); //logs ok
this.moving = true;
},
move: function(deltaTime){
// translations etc etc
}
});
云创建正常(通过日志记录确认并出现在场景中),它被告知开始移动正常(通过日志记录确认),但是 tick() 内的
只是永远不会触发,所以我无法让云移动!console.log
我是否没有正确使用泳池?或者这只是一种优化,以便池化实体即使在不使用时也不会全部滴答作响?我需要以某种方式激活它们吗?
任何帮助将不胜感激!谢谢大家。
-p
最佳答案
您可以尝试在池初始化后将管理器组件移动到初始化:
<a-entity
pool="mixin: cloud; size: 1;"
cloudmanager>
</a-entity>
它应该可以工作。查看this fiddle 。
<小时/> 池组件将在请求和返回实体时调用play
和 pause
。请求元素时,应在每个帧上调用 tick
函数。
关于javascript - 有没有办法在池化 A 型框架实体上启动 tick() 循环,或者我应该手动管理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55973248/