Note that there are some explanatory texts on larger screens.

plurals
  1. POFrame number equalling number -- Health Bar
    primarykey
    data
    text
    <p>I have created a bar where it is full on frame 1, then empty on frame 100, and I've made it into a shape tween. I want to create a code where when I press a certain button, it depletes the bar, so the frame goes from 1 until it reaches 100 as long as a certain button is held.</p> <p>I was thinking of a way to do this, but it seems impossible.</p> <pre><code>var maxHP:int = 100; var currentHP:int = maxHP; var percentHP:Number = currentHP / maxHP; </code></pre> <p>I would like to have the percentHP var equal the bar, so as it gets to 50, it'll reach frame 50, and so on.</p> <p>Is this the correct way of going about this?</p> <p>Thanks.</p> <hr> <p>Here are the variables being used in the code I'm trying to fix below. Also, the game I'm creating has multiple characters, so the bar I'm referring to is within a couple of movieclips.</p> <p>Basically, when the character double jumps, it is flying, and the bar depletes. Once the bars depletes to 0(Or when PercentHP is 0) then it should end the flying. Afterwards, I would like the bar to fill back up towards 100 overtime.</p> <pre><code>var percentHP = Number(Bar.CBar.CMana_bar.currentFrame) / Number(100); var gravityConstant:Number = 1; var doubleJumpReady:Boolean = false; var flyingJump:Boolean = false; var upReleasedInAir:Boolean = false; function loop(e:Event):void{ //Flying if(upReleasedInAir == true){ // if the player releases the up arrow key upReleasedInAir = false; // set the variable to true } if(doubleJumpReady == false){ doubleJumpReady = true; } } else { //if we are not touching the floor ySpeed += gravityConstant; //accelerate downwards //Flying if(upPressed == false &amp;&amp; upReleasedInAir == false){ upReleasedInAir = true; //trace("upReleasedInAir"); } if(doubleJumpReady &amp;&amp; upReleasedInAir){ if(upPressed){ //and if the up arrow is pressed flyingJump = true; //trace("doubleJump!"); doubleJumpReady = false; ySpeed = jumpConstant + 8; //set the y speed to the jump constant gravityConstant = 0; Bar.CBar.CMana_bar.play(); //trace(percentMP); } } if(Bar.CBar.CMana_bar.currentFrame == 100 &amp;&amp; percentHP == 0){ gravityConstant = 1; Bar.CBar.CMana_bar.stop(); flyingJump = false; doubleJumpReady = false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload