Batzi Posted October 6, 2015 Share Posted October 6, 2015 I have a typewriter function that takes text and the text length as parameters and prints a character every 100ms. I have a text objectvar text = game.add.text(0,0,'Hello',style);and its lengthvar n = text.text.length;and the functiontypeWriter(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 More sharing options...
Batzi Posted October 6, 2015 Author Share Posted October 6, 2015 nvm I fixed it. Link to comment Share on other sites More sharing options...
jmp909 Posted October 6, 2015 Share Posted October 6, 2015 post your code (helps others) and mark fixed please. it keeps the forum organised Link to comment Share on other sites More sharing options...
Batzi Posted October 7, 2015 Author Share Posted October 7, 2015 So basically I have a global variable innerTextinnerText = '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 functionfunction 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 More sharing options...
jmp909 Posted October 7, 2015 Share Posted October 7, 2015 I think you can just writesetTimeout(typeWriter,100);No need to create an anonymous inline function Link to comment Share on other sites More sharing options...
Recommended Posts