Jump to content

Handle Button Click


FahrulID
 Share

Recommended Posts

How Can I Handle Button Click 

 

nextbtn = game.add.button(game.world.width/2 - 97, game.world.height - 71, 'nextbtn', nextnext, this, 2, 1, 0);

function nextnext() {
	nextLine();
}

        var content = [
		"The sky above the port was the color of television, tuned to a dead channel.",
		"`It's not like I'm using,' Case heard someone say, as he shouldered his way ",
		"through the crowd around the door of the Chat. `It's like my body's developed",
		"this massive drug deficiency.' It was a Sprawl voice and a Sprawl joke.",
		"The Chatsubo was a bar for professional expatriates; you could drink there for",
		"a week and never hear two words in Japanese.",
		];
		
		var line = [];

		var wordIndex = 0;
		var lineIndex = 0;

		var wordDelay = 120;
		var lineDelay = 400;

		function nextLine() {

			if (lineIndex === 4)
			{
			//  We're finished
			return;
			}

		//  Split the current line on spaces, so one word per array element
		line = content[lineIndex].split(' ');

		//  Reset the word index to zero (the first word in the line)
		wordIndex = 0;

		//  Call the 'nextWord' function once for each word in the line (line.length)
		game.time.events.repeat(wordDelay, line.length, nextWord, this);
		
		//  Advance to the next line
		lineIndex++;

		}

		function nextWord() {

		//  Add the next word onto the text string, followed by a space
		text.text = text.text.concat(line[wordIndex] + " ");

		//  Advance the word index to the next word in the line
		wordIndex++;

		//  Last word?
		if (wordIndex === line.length)
		{
			//  Add a carriage return
			text.text = text.text.concat("\n");

			//  Get the next line after the lineDelay amount of ms has elapsed
			game.time.events.add(lineDelay, nextLine, this);
		}}
		
		
    };

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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