我正在使用A框架,并试图生成池多个'云'实体,这些实体将在激活一旦激活,但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>
应该有效。在此小提琴中检查一下。
池组件将在请求和返回实体后调用
play
和pause
。当请求元素时,应在每个帧上调用tick
函数。