Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to fade things in and out with CSS (Sugarcube)

Howler.js seems like a godsend on first glance. It does exactly what I need to do for all my projects both current and future. Only problem is, I can't seem to get it to work, probably because I'm a doofy idiot baby who don't know from code. I assume I need both the audio file and howler.min.js in the folder where the twine project is saved? And I'm not sure what to do from there. I tried opening howler.min.js in notepad, copying all that stuff, and pasting it in a passage tagged script, but I'm not sure that did anything meaningful.

For the record, I do know the difference between Java and Javascript. Also look forward to my sequel thread about lettering.js, which will be even more fun cause it's jquery. I don't even know what the eff that is.

Comments

  • This blog post discusses how to add Howler to Twine: http://videlais.com/2014/01/18/using-html5-audio-in-twine/

    Though you might also want to take a look at SugarCube. The latest update added in some powerful audio macros that I think are better than Howler's.
  • Oh wow, SucarCube is a hell of a thing. I'm definitely gonna play around with that.  A few questions:

    The "cacheaudio" command seems particularly useful for a future project of mine where it's necessary for audio tracks to be in synch with visuals. Is there any way to have a loading bar that's actually tied to the loading of the audio? It would be easy enough to fake it by having something spin for however long it would take for the audio to load on a 3G connection (assuming that's the slowest high-speed internet speed), but I'd rather have something that actually shows the loading progress and allow the player to continue once it's loaded. EDIT: Having played around with it a little, I've discovered that there's a loading bar by default. It would be nice to know how to change the style, though. For example, if I wanted a spinning revolver cylinder rather than a bar.

    Second, is there any way to, and I'm sure there's a more technical word for this that I don't know, "dismiss" audio from the cache? Because let's say a project has hours of music, sfx, and voice acting. That's a lot of audio to store in memory. But if the story was broken up into discrete chapters, you could load only the audio you need for that chapter and then dismiss it when the chapter is done. Then when the player selects the next chapter, it loads the audio for that one, and so on. Is there any way to do that?

    Third, let's say I wanted to do a Metal Gear type thing where, when the player clicks on the menu option to start the chapter, a gunshot sound plays and the screen immediately cuts to black. I've found that to get a sound to play upon clicking a link, it's <<click "Start Chapter">><<audio "gunshot" play>><</click>>, but how would I get the screen to cut to black? That would be a CSS thing, right?

    Finally, I notice that looping audio doesn't loop perfectly. There's a delay when it starts again. Is there any way to alleviate this?
  • LucienLachance wrote:

    Second, is there any way to, and I'm sure there's a more technical word for this that I don't know, "dismiss" audio from the cache? Because let's say a project has hours of music, sfx, and voice acting. That's a lot of audio to store in memory. But if the story was broken up into discrete chapters, you could load only the audio you need for that chapter and then dismiss it when the chapter is done. Then when the player selects the next chapter, it loads the audio for that one, and so on. Is there any way to do that?

    Third, let's say I wanted to do a Metal Gear type thing where, when the player clicks on the menu option to start the chapter, a gunshot sound plays and the screen immediately cuts to black. I've found that to get a sound to play upon clicking a link, it's <<click "Start Chapter">><<audio "gunshot" play>><</click>>, but how would I get the screen to cut to black? That would be a CSS thing, right?

    Finally, I notice that looping audio doesn't loop perfectly. There's a delay when it starts again. Is there any way to alleviate this?


    There are things that could possibly be done to make long stories more efficient, but that's more a case I think of testing out your story and if any issues arise to present them to SugarCube's developer to take a look at. No point really worrying about things before they arise, since the problem would be best solved on the developer end.

    Looping audio is a problem common to every browser audio application. The best way around it is to account for it in the tracks you choose, by for example playing distinct songs as opposed to one long audio loop (which I think sounds better anyway, and slight pauses between distinct songs don't matter), or by having your audio loop fade in/fadeout at start and end so it sounds more natural.

    For cut to black I just solved this problem myself recently. You will need to make an image the size of your background (I just go with images 2560 x 1440 to accomodate as many browser styles as possible) and colour it pure black colour, then call it something like zzz.jpg.

    Then you link your menu option to a passage with macros called "ZZZ" like the following, assuming the name of the passage you really want to link to is "Continue":

    <<removeclass "html" "background">><<addclass "html" "zzz">><<timedcontinue 0.5s>><<goto "Continue">>
    Doing this means that when the person clicks on the menu item they'll first get forwarded to ZZZ, then the <<timedcontinue>> macro will convey them to their chosen passage 0.5 seconds later after the fade to black code has been given time to work.

    Then in your CSS you have the following, assuming "background" is the image you display normally:

    html.background {
    background: [img[images/background.jpg]] fixed;
    background-size: cover;
    min-height: 100%;
    height:100%;
    -webkit-transition: all 2s linear;
    transition: all 2s linear;
    }

    html.zzz {
    background: [img[images/zzz.jpg]] fixed;
    background-size: cover;
    min-height: 100%;
    height:100%;
    -webkit-transition: all 500ms linear;
    transition: all 500ms linear;
    }
    What this does is fade the background image to black, and then 0.5 seconds later advances the game to the very next passage (in my example above, called "continue"), then on that passage you just reverse it, removing the class "zzz" and adding the class "background" back.

    However you still need to go further. You also need to make the passage area invisible too, so you add this to your css:

    .passage.invisible {
    display: none;
    }
    and then you tag the "zzz" passage with the "invisible" tag, to get it to turn off the passage area during the transition.

    You can also go further and hide the UI bar during the switch too, so you add this to your "zzz" passage:

    <<addclass "#ui-bar" "hide">>
    and then this to the next passage after it:

    <<removeclass "#ui-bar" "hide">>
    Then have this in your CSS:

    #ui-bar.hide {
    opacity: 0;
    visibility: hidden;
    -webkit-transition: opacity 500ms ease-in, visibility 500ms step-end;
    transition: opacity 500ms ease-in, visibility 500ms step-end;
    }
    #ui-bar:not(.hide) {
    -webkit-transition: opacity 3s ease-in;
    transition: opacity 3s ease-in;
    }

    All this combined in SugarCube will fade everything to black then back again a couple seconds later.

    Note though you might also want to do something about the "body" CSS element. I have my "body" element permanently turned off (I personally don't see the point of it given that Twine does everything in the passage and html areas), so I cannot draw any examples for that. But it should be along the same lines of making it transparent during the transition like the passage area and adding and removing classes like:

    <<addclass "body" "invisible">>

    Where you might have some css like:

    body.invisible {
    background-color: transparent;
    }
    Then you just tell your fade-in passage to <<removeclass "body" "invisible">> if you want to display the body area. The "body" element is overlaid on top of the HTML element, so if you don't make it invisible during the transition (or invisible permanently), then you won't see the fade to black as it will get in the way.
  • Claretta wrote:


    There are things that could possibly be done to make long stories more efficient, but that's more a case I think of testing out your story and if any issues arise to present them to SugarCube's developer to take a look at. No point really worrying about things before they arise, since the problem would be best solved on the developer end.


    Right. No sense putting the cart before the horse.

    Claretta wrote:

    Looping audio is a problem common to every browser audio application. The best way around it is to account for it in the tracks you choose, by for example playing distinct songs as opposed to one long audio loop (which I think sounds better anyway, and slight pauses between distinct songs don't matter), or by having your audio loop fade in/fadeout at start and end so it sounds more natural.


    Different songs is definitely one way around it. I might have thought of a way to fake a seamless loop, but I need to test it.

    Claretta wrote:

    For cut to black I just solved this problem myself recently. You will need to make an image the size of your background (I just go with images 2560 x 1440 to accomodate as many browser styles as possible) and colour it pure black colour, then call it something like zzz.jpg.

    Then you link your menu option to a passage with macros called "ZZZ" like the following, assuming the name of the passage you really want to link to is "Continue":

    <<removeclass "html" "background">><<addclass "html" "zzz">><<timedcontinue 0.5s>><<goto "Continue">>
    Then in your CSS you have the following, assuming "background" is the image you display normally:


    html.background {
    background: [img[images/background.jpg]] fixed;
    background-size: cover;
    min-height: 100%;
    height:100%;
    -webkit-transition: all 2s linear;
    transition: all 2s linear;
    }

    html.zzz {
    background: [img[images/zzz.jpg]] fixed;
    background-size: cover;
    min-height: 100%;
    height:100%;
    -webkit-transition: all 500ms linear;
    transition: all 500ms linear;
    }
    What this does is fade the background image to black, and then 0.5 seconds later advances the game to the very next passage (in my example above, called "continue"), then on that passage you just reverse it, removing the class "zzz" and adding the class "background" back.

    However you still need to go further. You also need to make the passage area transparent too, so you add this to your css:

    .passage.invisible {
    background-color: transparent;
    }
    and then you tag the "zzz" passage with the "invisible" tag, to get it to turn off the passage area during the transition.

    You can also go further and hide the UI bar during the switch too, so you add this to your "zzz" passage:

    <<addclass "#ui-bar" "hide">>
    and then this to the next passage after it:

    <<removeclass "#ui-bar" "hide">>
    Then have this in your CSS:

    #ui-bar.hide {
    opacity: 0;
    visibility: hidden;
    -webkit-transition: opacity 500ms ease-in, visibility 500ms step-end;
    transition: opacity 500ms ease-in, visibility 500ms step-end;
    }
    #ui-bar:not(.hide) {
    -webkit-transition: opacity 3s ease-in;
    transition: opacity 3s ease-in;
    }

    All this combined in SugarCube will fade everything to black then back again a couple seconds later.

    Note though you might also want to do something about the "body" CSS element. I have my "body" element permanently turned off (I personally don't see the point of it given that Twine does everything in the passage and html areas), so I cannot draw any examples for that. But it should be along the same lines of making it transparent during the transition like the passage area and adding and removing classes like:

    <<addclass "body" invisible">>

    Where you might have some css like:

    body.invisible {
    background-color: transparent;
    }
    Then you just tell your fade-in passage to <<removeclass "body" "invisible">> if you want to display the body area. The "body" element is overlaid on top of the HTML element, so if you don't make it invisible during the transition (or invisible permanently), then you won't see the fade to black as it will get in the way.

    I'll be over here wrapping my mind around that.
  • Well in simple terms, all it's doing is transitioning to a pure black background and making everything else on top of the background invisible during the transition.
  • I cannot get the fade to black to work for the life of me. Linked below (because no matter how much I compress this folder it's too big to be attached) is the folder containing the project file I'm testing with, along with the images and sounds it uses. There must be something I'm getting terribly wrong.

    http://www.filedropper.com/sugarcubetest
  • I don't want to download anything from an external download site. You don't need to supply the whole thing if it's just a css problem.
  • That's the thing though, I don't know if it's a CSS, HTML, or SugarCube markup problem. Attached is just the project file. Maybe you can tell what's wrong without having to fully test it.
  • A silly question, you are using a <<timedcontinue>> macro in your ZZZ passage, where is this macro defined?

    Because it is not listed in the SugarCube documentation, not defined in the SugarCube 1.0.19 header file, and not defined within your sugarcubetest.tws file. So it does not appear to exist.
  • I probably should have mentioned that timedcontinue comes from the SugarCube replace macro set that you have to download from the SugarCube website: http://www.motoslave.net/sugarcube/

    The code, I posted, however, does come direct from my working story, so I know it works fine once you set everything up.
  • When you say "I cannot get the fade to black to work" do you mean:

    a. Your background image does not re-appear.

    This is because your Continue passage does not contain the follow as suggested by Claretta

    <<removeclass "html" "zzz">><<addclass "html" "background">>
    b. The side-bar does not hide and then reshow.

    This is because the time between the adding the hide class to  #ui-bar element and then removing it again is so short that it does not have time to do the transition. You can see this by removing <<removeclass "#ui-bar" "hide">> from the Continue passage.

    c. Some other problem.
  • greyelf wrote:

    b. The side-bar does not hide and then reshow.

    This is because the time between the adding the hide class to  #ui-bar element and then removing it again is so short that it does not have time to do the transition. You can see this by removing <<removeclass "#ui-bar" "hide">> from the Continue passage.


    The <<addclass "#ui-bar" "hide">> as it is located currently is causing this issue, since it is after the goto macro, instead of before. It should be before.

    <<removeclass "html" "background">><<addclass "html" "zzz">><<timedcontinue 0.5s>><<goto "Continue">><<addclass "#ui-bar" "hide">>
    should be:

    <<removeclass "html" "background">><<addclass "html" "zzz">><<addclass "#ui-bar" "hide">><<timedcontinue 0.5s>><<goto "Continue">>
    That said, after looking at the story, beyond that and the other problem greyelf mentioned, I feel the main cause of this issue is that you haven't installed the replace macros. It appears that the timedreplace macro simply isn't firing, which means the story skips over the fade to black instantly. Best guess is the transition is occurring, but currently so fast that you cannot see it.
  • The final file is too big to attach on the forums, but I fixed your story and got it to work by:


    1. Go back and check what I read about this earlier:

    Claretta wrote:

    You will need to make an image the size of your background


    Your black image needs to be the size of your background image. When I tested this story, it seemed your images did not match in size, making the transition a little wonky. E.g. if your background is 1356 x 1921 px, you would need a black background of exactly 1356 x 1921 px.


    2. Add to your start passage:

    <<addclass "html" "background">>
    Currently you're not transitioning from anything. You need the first image background in first to fade out from it. ;)


    3. Change the ZZZ passage to:

    <<removeclass "html" "background">><<addclass "html" "zzz">><<addclass "#ui-bar" "hide">><<timedcontinue 0.5s>><<goto "Continue">>
    You need to make sure you're putting in all code related to the transition before the timedcontinue. The timedcontinue governs how long the screen stays pure black. I.e. it's the middle of the fade to black, not the start.


    4. Include in your continue passage:

    <<removeclass "html" "zzz">><<removeclass "#ui-bar" "hide">><<addclass "html" "background">>
    You need to remove the black background and replace it with the image background after the transition.


    5. Create a new passage and tag it "script", then paste this in:

    /*! <<replacelink>> macro set for SugarCube */
    (function(){"use strict";var requiredSugarCubeBuild=3805;if(!version||!version.build||version.build<requiredSugarCubeBuild){throw new Error("<<replacelink>> macro set requires SugarCube build "+requiredSugarCubeBuild+" or greater, aborting load")}version.extensions["replacelinkMacroSet"]={major:1,minor:1,revision:5};function showVer(n,notrans){if(!n){return}n.innerHTML="";new Wikifier(n,n.tweecode);n.setAttribute("data-enabled","true");n.style.display="inline";n.classList.remove("revision-span-out");if(!notrans){n.classList.add("revision-span-in");if(n.timeout){clearTimeout(n.timeout)}n.timeout=setTimeout(function(){n.classList.remove("revision-span-in");n=null},1)}}function hideVer(n,notrans){if(!n){return}n.setAttribute("data-enabled","false");n.classList.remove("revision-span-in");if(n.timeout){clearTimeout(n.timeout)}if(!notrans){n.classList.add("revision-span-out");n.timeout=setTimeout(function(){if(n.getAttribute("data-enabled")==="false"){n.classList.remove("revision-span-out");n.style.display="none";n.innerHTML=""}n=null},1e3)}else{n.style.display="none";n.innerHTML="";n=null}}function tagcontents(b,starttags,desttags,endtags,k){function tagfound(i,e,endtag){for(var j=0;j<e.length;j++){if(a.indexOf("<<"+e[j]+(endtag?">>":""),i)===i){return e[j]}}}var l=0,c="",tg,a=b.source.slice(k);for(var i=0;i<a.length;i++){if(tg=tagfound(i,starttags)){l++}else if((tg=tagfound(i,desttags,true))&amp;&amp;l===0){b.nextMatch=k+i+tg.length+4;return[c,tg]}else if(tg=tagfound(i,endtags,true)){l--;if(l<0){return null}}c+=a.charAt(i)}return null}function revisionSpanHandler(g,e,f,b){function mkspan(vtype){h=insertElement(m,"span",null,"revision-span "+vtype);h.setAttribute("data-enabled",false);h.style.display="none";h.tweecode="";return h}var k=b.source.indexOf(">>",b.matchStart)+2,vsns=[],vtype=e,flen=f.length,becomes,c,cn,m,h,vsn;if(this.shorthand&amp;&amp;flen){while(f.length>0){vsns.push([f.shift(),this.flavour==="insert"?"gains":"becomes"])}}else if(this.flavour==="insert"||this.flavour==="continue"&amp;&amp;this.trigger==="time"){vsns.push(["","becomes"])}if(this.flavour==="continue"&amp;&amp;flen){b.nextMatch=k+b.source.slice(k).length;vsns.push([b.source.slice(k),vtype])}else{becomes=["becomes","gains"];c=tagcontents(b,begintags,becomes.concat(endtags),endtags,k);if(c&amp;&amp;endtags.indexOf(c[1])===-1){while(c){vsns.push(c);c=tagcontents(b,begintags,becomes,endtags,b.nextMatch)}c=tagcontents(b,begintags,["/"+e,"end"+e],endtags,b.nextMatch)}if(!c){throwError(g,"<<"+e+">>: cannot find a matching close tag");return}vsns.push(c);if(this.flavour==="continue"){k=b.nextMatch;b.nextMatch=k+b.source.slice(k).length;vsns.push([b.source.slice(k),""])}}if(this.flavour==="remove"){vsns.push(["","becomes"])}cn=0;m=insertElement(g,"span",null,e);m.setAttribute("data-flavour",this.flavour);h=mkspan("initial");vsn=vsns.shift();h.tweecode=vsn[0];showVer(h,true);while(vsns.length>0){if(vsn){vtype=vsn[1]}vsn=vsns.shift();h=mkspan(vtype);h.tweecode=vsn[0]}if(typeof this.setup==="function"){this.setup(m,g,e,f)}}function quantity(m){return m.children.length-1+(m.getAttribute("data-flavour")==="remove"?1:0)}function revisionSetup(m,g,e,f){m.className+=" "+f[0].replace(" ","_")}function keySetup(m,g,e,f){var key=f[0];m.setEventListener("keydown",function l(e){var done=!revise("revise",m);if(done){m.removeEventListener("keydown",l)}})}function timeSetup(m,g,e,f){function cssTimeUnit(s){if(typeof s==="string"){if(s.slice(-2).toLowerCase()==="ms"){return Number(s.slice(0,-2))||0}else if(s.slice(-1).toLowerCase()==="s"){return Number(s.slice(0,-1))*1e3||0}}throwError(g,"<<"+e+'>>: "'+s+'" is not a valid CSS time unit');return 0}var tm=cssTimeUnit(f[0]);setTimeout(function timefn(){var done=!revise("revise",m);if(!done){setTimeout(timefn,tm)}},tm)}function hoverSetup(m){var fn,noMouseEnter=document.head.onmouseenter!==null,m1=m.children[0],m2=m.children[1],gains=m2.className.indexOf("gains")>-1;if(!m1||!m2){return}m1.onmouseenter=function(e){var efp=document.elementFromPoint(e.clientX,e.clientY);while(efp&amp;&amp;efp!==this){efp=efp.parentNode}if(!efp){return}if(this.getAttribute("data-enabled")!=="false"){revise("revise",this.parentNode)}};m2.onmouseleave=function(e){var efp=document.elementFromPoint(e.clientX,e.clientY);while(efp&amp;&amp;efp!==this){efp=efp.parentNode}if(efp){return}if(this.getAttribute("data-enabled")!=="false"){revise("revert",this.parentNode)}};if(gains){m1.onmouseleave=m2.onmouseleave}if(noMouseEnter){fn=function(n){return function(e){if(!event.relatedTarget||event.relatedTarget!==this&amp;&amp;!(this.compareDocumentPosition(event.relatedTarget)&amp;Node.DOCUMENT_POSITION_CONTAINED_BY)){this[n]()}}};m1.onmouseover=fn("onmouseenter");m2.onmouseout=fn("onmouseleave");if(gains){m1.onmouseout=m2.onmouseout}}m=null}function mouseSetup(m){var evt=document.head.onmouseenter===null?"onmouseenter":"onmouseover";m[evt]=function(){var done=!revise("revise",this);if(done){this[evt]=null}};m=null}function linkSetup(m,g,e,f){var l=document.createElement("a"),p=m.parentNode;l.className="link-internal replaceLink";p.insertBefore(l,m);l.insertBefore(m,null);l.onclick=function(){var p,done=false;if(m&amp;&amp;m.parentNode===this){done=!revise("revise",m);scrollWindowTo(m)}if(done){this.parentNode.insertBefore(m,this);this.parentNode.removeChild(this)}};l=null}function visitedSetup(m,g,e,f){var done,sav=state.active.variables,os="once seen",d=m.firstChild&amp;&amp;(this.flavour==="insert"?m.firstChild.nextSibling:m.firstChild).tweecode;sav[os]=sav[os]||{};if(d&amp;&amp;!sav[os].hasOwnProperty(d)){sav[os][d]=1}else{for(var i=sav[os][d];i>0&amp;&amp;!done;i--){done=!revise("revise",m,true)}if(sav[os].hasOwnProperty(d)){sav[os][d]+=1}}}function insideDepartingSpan(elem){var r=elem.parentNode;while(!r.classList.contains("passage")){if(r.classList.contains("revision-span-out")){return true}r=r.parentNode}}function reviseAll(rt,rname){var rall=document.querySelectorAll(".passage [data-flavour]."+rname),ret=false;for(var i=0;i<rall.length;i++){if(!insideDepartingSpan(rall<i>)){ret=revise(rt,rall[i])||ret}}return ret}function revise(rt,r,notrans){function doToGainerSpans(n,fn){for(var k=n-1;k>=0;k--){if(rc[k+1].classList.contains("gains")){fn(rc[k],notrans)}else{break}}}var ind2,curr,next,ind=-1,rev=rt==="revert",rnd=rt.indexOf("random")>-1,fl=r.getAttribute("data-flavour"),rc=r.childNodes,cyc=fl==="cycle",rcl=rc.length-1;for(var k=0;k<=rcl;k++){if(rc[k].getAttribute("data-enabled")==="true"){ind=k}}if(rev){ind-=1}curr=ind>=0?rc[ind]:cyc?rc[rcl]:null;ind2=ind;if(rnd){ind2=(ind+Math.floor(Math.random()*rcl))%rcl}next=ind2<rcl?rc[ind2+1]:cyc?rc[0]:null;var docurr=rev?showVer:hideVer;var donext=rev?hideVer:showVer;var currfn=function(){if(!(next&amp;&amp;next.classList.contains("gains"))||rnd){docurr(curr,notrans);doToGainerSpans(ind,docurr,notrans)}};var nextfn=function(){donext(next,notrans);if(rnd){doToGainerSpans(ind2+1,donext,notrans)}};if(!rev){currfn();nextfn()}else{nextfn();currfn()}return cyc?true:rev?ind>0:ind2<rcl-1}var begintags=[],endtags=[];[{name:"insertlink",flavour:"insert",trigger:"link",setup:linkSetup},{name:"timedinsert",flavour:"insert",trigger:"time",setup:timeSetup},{name:"insertion",flavour:"insert",trigger:"revisemacro",setup:revisionSetup},{name:"later",flavour:"insert",trigger:"visited",setup:visitedSetup},{name:"keyinsert",flavour:"insert",trigger:"key",setup:keySetup},{name:"replacelink",flavour:"replace",trigger:"link",setup:linkSetup},{name:"timedreplace",flavour:"replace",trigger:"time",setup:timeSetup},{name:"mousereplace",flavour:"replace",trigger:"mouse",setup:mouseSetup},{name:"hoverreplace",flavour:"replace",trigger:"hover",setup:hoverSetup},{name:"revision",flavour:"replace",trigger:"revisemacro",setup:revisionSetup},{name:"keyreplace",flavour:"replace",trigger:"key",setup:keySetup},{name:"timedremove",flavour:"remove",trigger:"time",setup:timeSetup},{name:"mouseremove",flavour:"remove",trigger:"mouse",setup:mouseSetup},{name:"hoverremove",flavour:"remove",trigger:"hover",setup:hoverSetup},{name:"removal",flavour:"remove",trigger:"revisemacro",setup:revisionSetup},{name:"once",flavour:"remove",trigger:"visited",setup:visitedSetup},{name:"keyremove",flavour:"remove",trigger:"key",setup:keySetup},{name:"continuelink",flavour:"continue",trigger:"link",setup:linkSetup},{name:"timedcontinue",flavour:"continue",trigger:"time",setup:timeSetup},{name:"mousecontinue",flavour:"continue",trigger:"mouse",setup:mouseSetup},{name:"keycontinue",flavour:"continue",trigger:"key",setup:keySetup},{name:"cycle",flavour:"cycle",trigger:"revisemacro",setup:revisionSetup},{name:"mousecycle",flavour:"cycle",trigger:"mouse",setup:mouseSetup},{name:"timedcycle",flavour:"cycle",trigger:"time",setup:timeSetup},{name:"keycycle",flavour:"replace",trigger:"key",setup:keySetup}].forEach(function(e){e.handler=revisionSpanHandler;e.shorthand=["link","mouse","hover"].indexOf(e.trigger)>-1;macros[e.name]=e;macros.registerTags(e.name);begintags.push(e.name);endtags.push("/"+e.name,"end"+e.name)});macros["revertlink"]=macros["reviselink"]=macros["randomiselink"]=macros["randomizelink"]={handler:function(a,b,c){function disableLink(l){l.style.display="none"}function enableLink(l){l.style.display="inline"}function updateLink(l){if(l.className.indexOf("random")>-1){enableLink(l);return}var rall=document.querySelectorAll(".passage [data-flavour]."+rname),cannext,canprev,ind,r,fl;for(var i=0;i<rall.length;i++){r=rall[i];fl=r.getAttribute("data-flavour");if(insideDepartingSpan(r)){continue}if(fl==="cycle"){cannext=canprev=true}else{if(r.firstChild.getAttribute("data-enabled")==="false"){canprev=true}if(r.lastChild.getAttribute("data-enabled")==="false"){cannext=true}}}var can=l.classList.contains("revert")?canprev:cannext;(can?enableLink:disableLink)(l)}function toggleText(w){w.classList.toggle(rl+"Enabled");w.classList.toggle(rl+"Disabled");w.style.display=w.style.display==="none"?"inline":"none"}if(c.length<2){throwError(a,"<<"+b+">>: insufficient arguments (requires at least 2)");return}var l,rev,rname,rl="reviseLink",v="",end=false,out=false;rname=c.shift().replace(" ","_");l=insertElement(a,"a");l.className="link-internal "+rl+" "+rl+"_"+rname+" "+b;if(c.length>1&amp;&amp;c[0][0]==="$"){v=c[0].slice(1);c.shift()}switch(c[c.length-1]){case"end":end=true;c.pop();break;case"out":out=true;c.pop();break}var h=state.active.variables;for(var i=0;i<c.length;i++){var on=i===Math.max(c.indexOf(h[v]),0),d=insertElement(null,"span",null,rl+(on?"En":"Dis")+"abled");if(on){h[v]=c[i];l.setAttribute("data-cycle",i)}else{d.style.display="none"}insertText(d,c[i]);l.appendChild(d)}l.onclick=function(){reviseAll(b,rname);var t=this.childNodes,u=this.getAttribute("data-cycle")-0,m=t.length,lall;if((end||out)&amp;&amp;u>=m-(end?2:1)){if(end){var n=this.removeChild(t[u+1]||t[u]);n.className=rl+"End";n.style.display="inline";this.parentNode.replaceChild(n,this)}else{this.parentNode.removeChild(this);return}}else{toggleText(t[u]);u=(u+1)%m;if(v){h[v]=c[u]}toggleText(t[u]);this.setAttribute("data-cycle",u)}lall=document.getElementsByClassName(rl+"_"+rname);for(var i=0;i<lall.length;i++){updateLink(lall[i])}};disableLink(l);setTimeout(function(l){return function(){updateLink(l)}}(l),1);l=null}};macros["mouserevise"]=macros["hoverrevise"]={handler:function(a,b,c,d){var endtags=["/"+b,"end"+b],evt=window.onmouseenter===null?"onmouseenter":"onmouseover",t=tagcontents(d,[b],endtags,endtags,d.source.indexOf(">>",d.matchStart)+2);if(t){var rname=c[0].replace(" ","_"),h=insertElement(a,"span",null,"hoverrevise hoverrevise_"+rname),f=function(){var done=!reviseAll("revise",rname);if(b!="hoverrevise"&amp;&amp;done){this[evt]=null}};new Wikifier(h,t[0]);if(b==="hoverrevise"){h.onmouseover=f;h.onmouseout=function(){reviseAll("revert",rname)}}else{h[evt]=f}h=null}}};macros.registerTags("mouserevise");macros.registerTags("hoverrevise");macros["instantrevise"]={handler:function(a,b,c,d){reviseAll("revise",c[0].replace(" ","_"))}}})();
    Please note you [i]cannot put any non-javascript in the script passage. See Twine 1 installing javascript documentation for details.

    This is tested and works on my end with the story file you gave. To alter the speed of the transition you simply change the number in the <<timedcontinue>> macro. E.g. for a longer transition you might have <<timedcontinue 2s>>


    EDIT: Made substantial edits for completion.
  • Woah. TBH I kind of forgot about this thread for a while. I don't know the policy on thread-bumping here, but I'd just like to give a pre-emptive thanks. I haven't tried any of the stuff you guys suggested yet, but I don't want to seem like a greasy freebooter. I'll edit this post if/when this works.

    EDIT: Ok, so first off, I changed the thread title to more accurately reflect what this thread became.

    Second, I'm suuuuper close. Everything's almost perfect. There's only one thing wrong, and it's a Sugarcube thing, and not a fade in/out thing. I did things mostly as Claretta said, with a few modifications. First, I noticed that the UI bar and passage area were not fading out at the same time. I solved this by putting the "<<addclass "html" "zzz">>" macro inside the "<<click>>" macro, so the Start passage looks like this:
    <<nobr>><<addclass "html" "background">><<endnobr>>Your story will display this passage first. Edit it by double clicking it.

    <<click "link1">><<audio "cctgloop" loop play>><<addclass "html" "zzz">><<goto "ZZZ">><</click>>
    <<click "link2">><<audio "dlsgucredits" fadein>><</click>>
    Then, I set all the webkit transitions except for "htmkl.zzz" to 2s ease-in. I noticed that the passage text didn't fade in along with everything else, so using the same technique Claretta did for nvisible," I made the same kind of thing labeled "fadein" and added "fadein"as a tag on the Continue passage. The CSS now looks like this:
    html.background {
    background: [img[intellivision_big]] fixed;
    background-size: cover;
    min-height: 100%;
    height:100%;
    -webkit-transition: all 2s ease-in;
    transition: all 2s ease-in;
    }

    html.zzz {
    background: [img[zzz]] fixed;
    background-size: cover;
    min-height: 100%;
    height:100%;
    -webkit-transition: all 500ms linear;
    transition: all 500ms linear;
    }
    .passage.invisible {
    background-color: transparent;
    }

    .passage.fadein {
    -webkit-transition: all 2s ease-in;
    transition: all 2s ease-in;
    }
    #ui-bar.hide {
    opacity: 0;
    visibility: hidden;
    -webkit-transition: opacity 2s ease-in, visibility 2s step-end;
    transition: opacity 500ms ease-in, visibility 500ms step-end;
    }
    #ui-bar:not(.hide) {
    -webkit-transition: opacity 2s ease-in;
    transition: opacity 2s ease-in;
    }
    Because I did the  "<<addclass "html" "zzz">>" macro in the start passage, I don't need it in the ZZZ passage, so that looks like this:
    <<removeclass "html" "background">><<addclass "#ui-bar" "hide">><<timedcontinue 2.5s>><<goto "Continue">>
    The Continue passage is as Claretta said.

    The one thing that remains an issue (and this was only apparent when I changed the BG image to a red field) is that all the lines that the passage text appears on have a black background. There has to be a way to change that, right? Not to mention that the UI bar is always its own color rather than showing the BG image behind it.
  • In my story I'm ok with the passage fading at a different rate as it suits the aesthetic I'm going for.

    As for the "passages on black" issue, do you just mean the passage and ui background colour?

    You can put:

    background-color: transparent;
    In the various css areas like .passage, #body and #ui-bar, #ui-body if you don't want to show their native colour. You may also need to set the border property to transparent in the UI bar too.

    The way Twine is constructed, the body, passage, and UI elements are layered on top of the html background. So if you ever want to see the html background you need to turn off or make the top layers transparent.

    Oh and regarding the "invisible" passage, I realised when I wrote this thread I did something stupidly complicated like set all the elements to transparent. It's better to just write:

    .passage.invisible {
    display: none; }
    If you ever want to turn something completely off. Not sure if you saw my edit of that in time.
Sign In or Register to comment.