Jump to content

Text object in a TypeWriter


Batzi
 Share

Recommended Posts

I have a typewriter function that takes text and the text length as parameters and prints a character every 100ms.

 

I have a text object

var text = game.add.text(0,0,'Hello',style);

and its length

var n = text.text.length;

and the function

typeWriter(text.text, n);

Now I want to display that text object but I want to pass its text through a typeWriter function. Do you know if that's possible?

Link to comment
Share on other sites

So basically I have a global variable innerText

innerText = 'Hello this is Snake, do you read me Otacon?';

another variable for the loop which I use to keep count of the number of characters that are being printed (global variable)

n = 0;

the text object (global variable)

text = game.add.text(0,0,'',style); //leave the text empty (3rd parameter)

and the typeWriter function

function typeWriter(){  if(n<innerText.length){  text.text += innerText.charAt(n);  n++;  setTimeout(function(){    typeWriter()},100);  }}

This should work! It worked for me :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...