Reputation: 75
I'm using A-Frame and trying to generate pool multiple 'cloud' entities that will slowly begin moving in a particular direction once activated, but the tick()
function doesn't seem to be being called! Is there a way to kickstart it, or do I need to manage it manually?
Here's the setup that I'm using to test with 1 cloud:
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
}
});
The cloud gets created okay (confirmed with logging and appears in scene), it gets told to start moving okay (confirmed with logging), but the console.log
inside tick()
just never fires and so I can't get the cloud moving!
Am I not using the pool correctly? Or is this just an optimisation so that pooled entities aren't all ticking even when they're not used? Do I need to activate them in some way?
Any help would be hugely appreciated! Thanks all.
-p
Upvotes: 0
Views: 214
Reputation: 14655
You can try moving the manager component to initialize after the pool is initialized:
<a-entity
pool="mixin: cloud; size: 1;"
cloudmanager>
</a-entity>
And it should be working. Check it out in this fiddle.
play
and pause
upon requesting and returning entities. When an element is requested, the tick
function should be called on each frame.
Upvotes: 1