Previously I was experimenting with alternatives to Twine's default fade-in animation. Now, I've figured out how to make such alterations with a single block of JavaScript insertion that you can drop into your story.
Here's a block of code that, when inserted into a Sugarcane formatted Twine game, changes the passage transition to a dissolve, where the previous passage fades out at the same time as the next passage fades in.
[Note: This will not work with the one-page Jonah format.]
addStyle(".passage { position:absolute !important; } ");
History.prototype.display = function (d, b, a) { var c = tale.get(d);
this.history.unshift({
passage: c,
variables: clone(this.history[0].variables)
});
this.history[0].hash = this.save();
var e = c.render();
if(a != "offscreen") {
var f = $("passages").firstChild;
if (f) fade(f, {fade: "out", onComplete: function(){$("passages").removeChild($("passages").firstChild)} });
$("passages").appendChild(e);
if(a != "quietly") {
fade(e, {fade: "in"})
}
}
if((a == "quietly") || (a == "offscreen")) {
e.style.visibility = "visible"
}
if(a != "offscreen") {
document.title = tale.title;
this.hash = this.save();
document.title += ": " + c.title;
window.location.hash = this.hash;
window.scroll(0, 0)
}
return e
};
History.prototype.watchHash = function () {
if(window.location.hash != this.hash) {
if((window.location.hash != "") && (window.location.hash != "#")) {
this.history = [{
passage: null,
variables: {}
}];
$("passages").style.visibility = "hidden";
if(!this.restore()) {
alert("The passage you had previously visited could not be found.")
}
$("passages").style.visibility = "visible"
}
else {
window.location.reload()
}
this.hash = window.location.hash
}
};
Just put this in a vacant passage tagged with "script".
Note that in order to do this, it will set the passage divs to use the style "position: absolute", so keep that in mind if you're using CSS that requires a different positioning.
What this actually does is replace the Twine engine's History.prototype.display function with an alternative version that sets the previous passage to fade out and then be removed, instead of just immediately removing it. Since the passage divs are set to absolute positioning, they're drawn one top of the other while they simultaneously exist, instead of being vertically arranged.
This also replaces History.prototype.watchHash, which controls the Back button behaviour. Again, this is simply to keep the previous passage(s) from being removed immediately, and instead letting History.prototype.display do it. (If you're using a hack that modifies History.prototype.watchHash, you will probably have to do some tweaking to this or the other to get this to work.)
See attachment for an example (applied to "Town" by Anna Anthropy).) { fade(e, {fade:
Attachment | Size |
---|---|
town_dissolve.html | 47.79 KB |