triangle now hides while typewriting

This commit is contained in:
Yannik
2023-05-26 22:31:32 +02:00
parent ad61ec342b
commit d192958849
2 changed files with 15 additions and 8 deletions

View File

@@ -10,7 +10,7 @@
<title>TextHorror</title>
</head>
<body onpageshow="load()" onclick="mouseClick()">
<body onpageshow="load()" onmouseup="mouseUp()" onmousedown="mouseDown()">
<div id="bubble"></div>
<img id="triangle" src="text_horror/assets/triangle.png">
<p class="thx-for-playing">Thanks for playing</p>

View File

@@ -15,20 +15,27 @@ function load() {
}
function typeWriter() {
if (document.getElementById("bubble").innerHTML.length - 1 < dlgLines[dlgPointer].toString().length) {
if (document.getElementById("bubble").innerHTML.length < dlgLines[dlgPointer].toString().length) {
document.getElementById("bubble").innerHTML += dlgLines[dlgPointer].toString().charAt(typeindex);
typeindex++;
setTimeout(typeWriter, speed);//loops because of running "typeWriter" after waiting
document.getElementById("triangle").hidden = document.getElementById("bubble").innerHTML.length != dlgLines[dlgPointer].length
setTimeout(typeWriter, speed); //loops because of running "typeWriter" after waiting
}
}
function mouseClick() {
if (document.getElementById("bubble").innerHTML.length == dlgLines[dlgPointer].length) {
if (dlgPointer < dlgLines.length - 1) {
dlgPointer++;
while (!(typeof dlgLines[dlgPointer] === 'string')) dlgPointer++;//again if it's not string
function mouseDown() {
document.getElementById("triangle").hidden = true;
}
function mouseUp() {
if (document.getElementById("bubble").innerHTML.length == dlgLines[dlgPointer].length) { //check if text is typed out
if (dlgPointer < dlgLines.length - 1) { //check if dlgPointer is not at the array end
do
dlgPointer++;
while (!(typeof dlgLines[dlgPointer] === 'string')) //again if it's not string
typeindex = 0;
document.getElementById("bubble").innerHTML = "";
document.getElementById("triangle").hidden = true;
typeWriter();
} else {
document.getElementById("bubble").hidden = true;