Thanks @Leonidas! That’s a really clean way of doing it. I’ve not got it quite working yet. Are you able to have a look and let me know where I’ve gone wrong? Is the time in seconds?
I took a look at your project. I believe there are a couple of issues here:
Ui.prototype.initialize = function() {
var div = document.createElement("div");
div.id = "ui";
div.innerHTML = this.html.resource;
document.body.appendChild(div);
style = pc.createStyle(this.css.resource);
document.head.appendChild(style);
};
// initialize code called once per entity
Ui.prototype.tweenOpacity = function(entity, from, to, time, onComplete) {
var opacity = {value: 1};
entity
.tween(opacity)
.to({value: 0}, 2, pc.SineOut)
.on('update', function() { entity.element.opacity = opacity.value; }.bind(this))
.start();
};
The first of which is that it doesn’t look like anything ever calls the tweenOpacity() function. At least not in the scripts I see.
I’m also not too sure about the setup here since it doesn’t seem like you’re using most of the arguments in your function setup.
I could make some recommendations, but first it would help to understand the intended behavior. What would be controlling/triggering the fade and when should it happen?
Many thanks for taking a look. I’m looking at making the instructions disappear after a few seconds. These are currently set as an entity parented to the player and using the ui.js.
Ohhhhh ok. This is actually another problem entirely. I didn’t realize you were actually trying to fade a <div> instead of a Playcanvas element. That will change how your code has to be factored quite a bit. Here is how I made it work: