Hi,
In my scene I want to use text bubbles. I made it work but now I want to make it disappear after a certain amount of seconds. Easy, I thought. I’ll just use a setTimeOut function and disable the entity.
That works. The problem is; when re-enabling the entity, the text is not visible anymore.
The entity has a text element component and a sprite component. The sprite component is visible when re-enabling the entity.
The typeWriter function is called when clicking on a character.
Here is my code:
DialogueManager.prototype.typeWriter = function (characterName, textBubbleEntity, newText) {
textBubbleEntity.enabled = true;
// Assign the new text to the textbubble text
textBubbleEntity.element.text = newText;
// This makes the sprite responsive to the amount of text
textBubbleEntity.sprite.width = (textBubbleEntity.element.width + 20);
textBubbleEntity.sprite.height = (textBubbleEntity.element.height + 20);
// Start with no text printed
textBubbleEntity.element.rangeStart = 0;
textBubbleEntity.element.rangeEnd = 0;
// Render a new character every 40ms
var interval = setInterval(function () {
textBubbleEntity.element.rangeEnd += 1;
textBubbleEntity.sprite.height = (textBubbleEntity.element.height + 20);
// Check if all text is shown
if (textBubbleEntity.element.rangeEnd >= newText.length) {
clearInterval(interval);
console.log("end reached");
setTimeout(function(){
textBubbleEntity.enabled = false;
console.log("1 second delay");
}, 1000);
}
}.bind(this), 40);
};
Here is a quick video to show what is going on.
Here is the project link:
https://playcanvas.com/editor/scene/1354661
(You have to start in the master scene)
Does anybody have a clue why the text is not showing?