Advertisement
nutter666

Healthbar Code

Sep 16th, 2018
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.     import flash.display.Sprite;
  3.    
  4.     public class HealthBar extends Sprite{
  5.        
  6.         var colour1;
  7.         var colour2;
  8.         var barWidth:int;
  9.         var barHeight:int;
  10.  
  11.         public function HealthBar() {
  12.             // constructor code
  13.         }
  14.        
  15.         function initBar(col1,col2,barW,barH){
  16.         this.colour1 = col1
  17.         this.colour2 = col2;
  18.         this.barHeight = barH
  19.         this.barWidth = barW;
  20.         }
  21.        
  22.         function updateBar(currentHP:Number,maxHP){
  23.         this.graphics.clear();
  24.        
  25.         this.graphics.beginFill(colour2,1)
  26.         this.graphics.drawRect(0,0,  barWidth,barHeight)
  27.        
  28.         this.graphics.beginFill(colour1,1)
  29.         this.graphics.drawRect(0,0,barWidth *(currentHP/maxHP),barHeight)
  30.        
  31.         //this.graphics.lineStyle(1,0xFF0000,1)
  32.         this.graphics.endFill();
  33.         this.graphics.drawRect(-1,-1,  barWidth+1,barHeight+1)
  34.         }
  35.  
  36.     }
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement