Hi,
I have a game object that plays an animation when the player touches it.
I would like this object to be idle: don’t play the animation until it is asked to.
My issue here is that if I enable the activate
checkbox in the editor, the animation plays automatically when the scene is loaded.
If I disable the checkbox, the model does not even show up until I call animation.play("name")
.
How can I have my model be displayed on the scene, and the animation stopped on the first frame until I call play
?
I have tried a few things and managed to make it “work”, but this is veryyyy ugly:
var emptyfunction = function() {};
Bumper.prototype.initialize = function() {
this.entity.collision.on('collisionstart', this.onTriggerEnter, this);
this.model = this.entity.findByName("Model");
};
Bumper.prototype.onTriggerEnter = function(e) {
// now that I call animation.play(), I can remove the update function that stops on first frame
this.update = emptyfunction;
this.model.animation.play("anim.json");
};
// force the object to be stopped on the first frame
Bumper.prototype.update = function(dt) {
this.model.animation.currentTime = 0;
};
Is there a more efficient/proper way to do it?