Hey,
Two key things you need to do (with Javascript).
- Create the image pane when the story begins
- Adjust the contents (or hide) the image pane at the start of each passage.
Creating the Image Pane
Add this line to your Story Javascript.
$("<div id='npc'></div>").insertAfter($("#story"));
This will create a new DIV element with the ID npc
right after the main story DIV in your game’s HTML. That DIV will persist for the entire course of the story.
In order to get it to display where you want, put something like this in the Story Stylesheet.
#npc
{
position: fixed;
top: 0;
right: 0;
width: 300px;
background-color: red;
height: 100%;
}
That’ll make it appear fixed on the right side of the screen. I made the background red for now just so you can clearly see it. You’ll need to tweak this to your own needs, of course. You’ll also have to deal with adjusting the margins on the story text to make sure the text doesn’t go underneath the image area (we can work on that later).
Okay, now we have our image pane.
Putting Content in the Pane
There’s a couple ways to do this, it really depends on how you want to structure your story. I’ll try to keep it open to tweaking.
Add the following to your story Javascript
// Runs every time a new passage is rendered.
// Happens at the end of the passage processing,
// so you'll have the latest variables set by the passage.
$(document).on(":passagerender", function(ev) {
// If the Twine variable $showNPC is set to true
if(variables().showNPC) {
// Render NPC_PASSAGE into the #npc element
setPageElement("npc", "NPC_PASSAGE");
// Make sure it's visible
$("#npc").show();
}
else {
// Otherwise, hide the elemement
$("#npc").hide();
}
});
After each new passage, this will check if the variable $showNPC is set. If it is, your NPC panel will be set to visible and the contents of the passage NPC_PASSAGE
will get freshly rendered into it. $showNPC is not defined or false, it’ll be hidden.
Make sure to actually create a passage called NPC_PASSAGE and check it out. From that passage, you can check things like what NPC is talking and display the correct image.
There’s plenty of ways to customize this. You could, for example, dynamically choose what passage to render in setPageElement
depending on various variables.