Recharging Stamina

A place for tutorials on how to get the most out of Flash

Recharging Stamina

Postby hat973 » Mon Jul 06, 2015 8:37 pm

I'm doing some side work on my game and I like a stamina bar to be on screen and when the player runs the bar drains and when the player is done running the bar refills from the spot in stopped or when it was empty the player stops running. I'd also like the bar to kinda go threw a reset thing after a grab deal seeing as it takes Stamina to have sex. So the question is how would I make a bar that would fit all of those things?
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am

Re: Recharging Stamina

Postby GoRepeat » Tue Jul 07, 2015 6:12 am

Create a variable to track stamina and max stamina. Have your bar be 101 frame movie clip where 0 is no bar and 101 is a full bar. Set the bar to current stamina / max stamina +1. Reduce the current stamina variable while running. Create a condition that if stamina <= 0, running stops and/or is unavailable. After a sex animation set current stamina = max stamina to reset it to full and start all over again.

Code: Select All Code
var currStam:int = 100;
var maxStam:int = 100;
var stamBar:MovieClip = new staminaBar();
stamBar.gotoAndStop(Math.floor(currStam/maxStam)+1);

//while running button is pressed
switch(true){
   case currStam >0: currStam -= 1; stamBar.gotoAndStop(Math.floor(currStam/maxStam)+1); charRun(); break;
   default: currStam = 0; break;
}

//after sex
currStam = maxStam;
stamBar.gotoAndStop(Math.floor(currStam/maxStam)+1);


Something like that
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Recharging Stamina

Postby NoBounce16 » Sun Feb 14, 2016 12:17 am

To add to this, you could also do any progress bar pragmatically rather than through a movieclip animation to save on memory. I would probably create a new ProgressBar class that looks a little bit like this:

Code: Select All Code
package
{
   import flash.display.Shape;
   import flash.geom.ColorTransform;

   public class ProgressBar extends Shape
   {
      private var colors:Array=[0x99DC57, 0xF38230, 0xF33E30];
      public function ProgressBar(barWidth:int, barHeight:int)
      {
         this.graphics.beginFill(colors[0], 1);
         this.graphics.drawRect(0,0,barWidth, barHeight);
         this.graphics.endFill();
      }
      
      public function updateProgressBar(stamina:int):void{
         var my_color:ColorTransform = new ColorTransform();
         if(stamina > 80){
            my_color.color = colors[0];
         } else if(stamina > 30) {
            my_color.color = colors[1];
         } else {
            my_color.color = colors[2];
         }
         
         this.scaleX = stamina/100;
         this.transform.colorTransform = my_color;
         my_color = null;
      }
      
      public function dispose():void{
      }
   }
}


I haven't tested this, so just check syntax before trying it out. Set the colours in the array to what colours you want the health bar to be at different points. You could update the 'updatebar' method to a switch statement but I don't really see the point if you're just handling a few different colours. Make sure, if you're adding text or various other things, you include a 'dispose' method to clean up everything because the garbage collection on Flash can be a bit shitty - just remove all children and set everything in the class to null / empty. I think this forum needs to stop overusing frames as it causes big load issues with a lot of the games I've seen.

To use this, you'd initialize it like this:

Code: Select All Code
var progressbar:ProgressBar = new ProgressBar(150, 20);
addChild(progressbar);
progressbar.updateProgressBar(90);


Hope this helps!
NoBounce16
Newly Registered
 
Joined: Thu Feb 11, 2016 11:38 am


Return to Tutorials



Who is online

Users browsing this forum: No registered users