Skip to content

Commit

Permalink
Fix for issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
netgfx committed May 8, 2016
1 parent 700f819 commit 08ab1c5
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions typewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function Typewriter() {
this.pickedQuote;
var _that = this;
var game;

function init(gameInstance, options) {
game = gameInstance;
_that.time = options.time || Phaser.Timer.SECOND / 10;
Expand All @@ -24,6 +25,19 @@ function Typewriter() {
enableTypingSpecificMessage(_that.text, _that.x, _that.y);
}

function stop() {
if (_that.timer !== undefined) {
_that.timer.stop();
game.time.events.remove(_that.timer);
}
if (_that.sound !== null) {
_that.sound.stop();
}
if(_that.typedText !== undefined){
_that.typedText.destroy();
}
}

function enableTypingSpecificMessage(text, x, y) {

if (_that.writerObj === null) {
Expand All @@ -35,7 +49,7 @@ function Typewriter() {
_that.currentLetter = 0;
var length = _that.typedText.children.length;

for (var i = 0; i < length; i++){
for (var i = 0; i < length; i++) {
var letter = _that.typedText.getChildAt(i);
letter.alpha = 0;
}
Expand All @@ -62,14 +76,15 @@ function Typewriter() {
function countdown(fn, times, endFn) {
var _timer = game.time.create(false);
_timer.start();
endFn = endFn || function () {
endFn = endFn || function() {
game.time.events.remove(_timer);
if (_that.sound !== null) {
_that.sound.stop();
}
};
_timer.onComplete.add(endFn);
_timer.repeat(_that.time, times, fn, this);
_that.timer = _timer;
}

function typeWriter(text) {
Expand All @@ -84,10 +99,11 @@ function Typewriter() {
}

return {
init: function (gameInstance, options) {
init: function(gameInstance, options) {
init(gameInstance, options);
},
start: function () {
start: function() {
stop();
start();
},
destroy: function() {
Expand All @@ -103,4 +119,4 @@ function Typewriter() {
game.bringToTop(_that.typedText);
}
}
}
}

0 comments on commit 08ab1c5

Please sign in to comment.