Hello there.
I wanted to add an energy bar to my current game, so I looked for info on this Q&A and found this : http://twinery.org/questions/4464/trouble-with-energy-bar-it-just-wont-decrease
Greyelf helped MrPepperMint by offering a working solution for an energy bar.
Yet, I can't seem to make it work myself...
The energy bar does appear within the Story Caption, but despite my efforts, I didn't manage to have its length reduced when using <<set $EnergyLoss to 50>>. The bar won't change.
I even tried to create a new story only to try out the bar, and still, I can't have the bar working.
Any idea what I am doing wrong here ?
Thanks a lot
I am using SugarCube 2. something
StoryCaption
<div class="energy-bar">\
<div class="bar"></div>\
</div>\
<<run setup.updateEnergyBar()>>
Story Stylesheet
energy-bar {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 200px;
height: 20px;
padding: 5px;
background: #ddd;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
position: relative;
}
.bar {
background: #c54;
width: 100%;
height: 10px;
position: relative;
transition: width .5s linear;
}
Story Javascript
setup.updateEnergyBar = function () {
var
hBar = $('#story-caption .energy-bar'),
bar = hBar.find('.bar');
var
total = State.variables.EnergyTotal,
value = State.variables.Energy,
loss = State.variables.EnergyLoss,
barWidth = (value / total) * 100,
delayReset = false;
if (loss != 0) {
value -= loss;
barWidth = (value / total) * 100;
State.variables.Energy = value;
State.variables.EnergyLoss = 0;
delayReset = true;
}
hBar.data('total', total);
hBar.data('value', value);
bar.css('width', barWidth + "%");
if (delayReset) {
setTimeout(function(){
bar.css('width',
(State.variables.Energy / State.variables.EnergyTotal) * 100
+ "%");
}, 500);
}
};
I then created two passages, [[Passage 1]] where the story starts, leading to [[Passage 2]], where I <<set $EnergyLoss to 50>>, hoping for a change.