From 84f56b62bb9643f90e8a355e8b1079f03773e843 Mon Sep 17 00:00:00 2001 From: M3156 <m3156@student.jamk.fi> Date: Mon, 3 Feb 2020 14:51:44 +0200 Subject: [PATCH] finished the phaser course --- harkka3/samson/index.html | 1 + harkka3/samson/state8.js | 39 +++++++++++++++++++++++++++++++++++++-- index.html | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/harkka3/samson/index.html b/harkka3/samson/index.html index 6dcbc95..be5c70e 100644 --- a/harkka3/samson/index.html +++ b/harkka3/samson/index.html @@ -6,6 +6,7 @@ </title> <script src="phaser/phaser.min.js"></script> <link rel="stylesheet" href="main.css"> + <!-- <link href="https://fonts.googleapis.com/css?family=Dancing+Script:500&display=swap" rel="stylesheet"> --> <script src="state0.js"></script> <script src="state1.js"></script> <script src="state2.js"></script> diff --git a/harkka3/samson/state8.js b/harkka3/samson/state8.js index e106fd5..2dc3a02 100644 --- a/harkka3/samson/state8.js +++ b/harkka3/samson/state8.js @@ -1,9 +1,44 @@ +var text; + +WebFontConfig = { + google: { families: [ 'Dancing Script', 'Inconsolata' ] } +}; + demo.state8 = function(){}; demo.state8.prototype = { - preload: function(){}, + preload: function(){ + game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'); + }, create: function(){ game.stage.backgroundColor = '#000066'; addChangeStateEventListeners(); + + text = 'I know it seems hard sometimes but remember one thing. Through every dark night, there is a bright day after that. So no matter how hard it get, stick your chest out, keep ya head up.... and handle it.' + + this.spellOutText(100, 150, 1000, text, 50, 40, '#fff', 'Dancing Script'); + this.spellOutText(100, 550, 1000, text, 50, 20, '#ff0000', 'Inconsolata'); }, - update: function(){} + spellOutText: function(x, y, width, text, fontSize, speed, fill, font){ + var sentence = game.add.text(x, y, '', {fontSize: fontSize + 'px', fill: fill, font: font}); + var currentLine = game.add.text(10, 10, '', {fontSize: fontSize + 'px', font: font}); + currentLine.alpha = 0; + var loop = game.time.events.loop(speed, addChar); + + var index = 0; + + function addChar(){ + sentence.text += text[index]; + currentLine.text += text[index]; + + if(currentLine.width > width && text[index] == ' ') { + sentence.text += '\n'; + currentLine.text = ''; + } + if (index >= text.length -1) { + game.time.events.remove(loop); + console.log('stop'); + } + index++; + } + } } \ No newline at end of file diff --git a/index.html b/index.html index 44665cf..6ead711 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ <h2>Samson Azizyan (M3156)</h2> <a href="https://gitlab.labranet.jamk.fi/M3156/ttos0700-peliohjelmointi">GIT repo</a><br> <a href="http://m3156.pages.labranet.jamk.fi/ttos0700-peliohjelmointi/harkka2/phaser-game-1.html">Harkka 2 - Ensimmäinen Phaser-peli</a><br> - <a href="http://m3156.pages.labranet.jamk.fi/ttos0700-peliohjelmointi/harkka3/samson/">Harkka 3 - Dick on the Beach (state 0 - 3)</a> + <a href="http://m3156.pages.labranet.jamk.fi/ttos0700-peliohjelmointi/harkka3/samson/">Harkka 3 - Udemy Phaser kurssi (state 0 - 8)</a> </body> </html> \ No newline at end of file -- GitLab