forked from Chasmiccoder/acm-rpg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: Typewriter + change map animation
- Loading branch information
1 parent
cb1ec4b
commit df27df4
Showing
8 changed files
with
158 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class RevealingText { | ||
constructor(config) { | ||
this.element = config.element; | ||
this.text = config.text; | ||
this.speed = config.speed || 60; // larger value = slower typing speed | ||
|
||
this.timeout = null; | ||
this.isDone = false; | ||
} | ||
|
||
// recursively reveal all characters in the list | ||
revealOneCharacter(list) { | ||
const next = list.splice(0,1)[0]; | ||
next.span.classList.add("revealed"); | ||
|
||
if(list.length > 0) { | ||
this.timeout = setTimeout(() => { | ||
this.revealOneCharacter(list); | ||
}, next.delayAfter); | ||
} else { | ||
this.isDone = true; | ||
} | ||
} | ||
|
||
// Reveal all the spans if the user hits Enter | ||
warpToDone() { | ||
clearTimeout(this.timeout); | ||
this.isDone = true; | ||
this.element.querySelectorAll("span").forEach(s => { // NOTE! This might mess with the front end css | ||
s.classList.add("revealed"); | ||
}); | ||
} | ||
|
||
init() { | ||
let characters = []; | ||
// "abc" -> ["a", "b", "c"] | ||
this.text.split("").forEach(character => { | ||
|
||
// create each span, and add to element in DOM | ||
let span = document.createElement("span"); | ||
span.textContent = character; | ||
this.element.appendChild(span); | ||
|
||
// Add span to internal state array | ||
characters.push({ | ||
span, | ||
delayAfter: character === " " ? 0 : this.speed // don't add a timeout for spaces (better presentation this way) | ||
}); | ||
|
||
}); | ||
|
||
this.revealOneCharacter(characters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class SceneTransition { | ||
constructor() { | ||
this.element = null; | ||
|
||
} | ||
|
||
createElement() { | ||
this.element = document.createElement("div"); | ||
this.element.classList.add("SceneTransition"); | ||
} | ||
|
||
fadeOut() { | ||
this.element.classList.add("fade-out"); | ||
this.element.addEventListener("animationend", () => { | ||
this.element.remove(); | ||
}, {once: true}); | ||
} | ||
|
||
init(container, callback) { | ||
this.createElement(); | ||
container.appendChild(this.element); | ||
|
||
// to know if the animation is done, (so that we can callback) | ||
this.element.addEventListener("animationend", () => { | ||
callback(); | ||
}, {once: true}); // shouldn't fire again, when we have the fade out | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
How the change map transition works: | ||
old map fades to white | ||
from a white bg, the new map fades into existence | ||
*/ | ||
|
||
.SceneTransition { | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
background: #fff; | ||
opacity: 0; | ||
animation: scene-transition-fade-in 0.3s forwards; | ||
} | ||
|
||
.SceneTransition.fade-out { | ||
animation: scene-transition-fade-out 0.3s forwards; | ||
} | ||
|
||
@keyframes scene-transition-fade-in { | ||
from { opacity: 0; } | ||
to { opacity: 1; } | ||
} | ||
|
||
@keyframes scene-transition-fade-out { | ||
from { opacity: 1; } | ||
to { opacity: 0; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters