-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlxPlayState.as
62 lines (49 loc) · 1.55 KB
/
FlxPlayState.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package org.flixel
{
public class FlxPlayState extends FlxState
{
public var player:FlxSprite;
public var hud:FlxGroup;
private var hpBar:FlxSprite;
private var hpBarFrame:FlxSprite;
private var hpBarMax:Number;
public function FlxPlayState()
{
super();
hud = new FlxGroup();
add(hud);
for each (var h:FlxSprite in hud.members)
{
h.scrollFactor.x = h.scrollFactor.y = 0;
}
}
/**
* Add a healthbar to track the player objects health
*
* @param X : The X value of the HP Frame
* @param Y : The Y value of the HP Frame
* @param Width : The Width of the Frame
* @param Height : The Height of the Frame
* @param BarColor : The color of the bar
* @param FrameColor : The color of the frame
*/
public function addHealthBar(X:Number = 5, Y:Number = 5, Width:Number = 100, Height:Number = 10, BarColor:uint=0xFFFFFFFF, FrameColor:uint=0xFF000000):void
{
hpBarFrame = new FlxSprite(X, Y);
hpBarFrame.createGraphic(Width, Height, FrameColor);
//hpBarFrame.scrollFactor.x = hpBarFrame.scrollFactor.y = 0;
hud.add(hpBarFrame);
hpBarMax = Width - 2;
hpBar = new FlxSprite(hpBarFrame.x+1, hpBarFrame.y+1);
hpBar.createGraphic(1,Height - 2, BarColor);
//hpBar.scrollFactor.x = hpBar.scrollFactor.y = 0;
hpBar.origin.x = hpBar.origin.y = 0;
hpBar.scale.x = hpBarMax;
hud.add(hpBar);
}
public function updateHealthBar():void
{
hpBar.scale.x = (player.health/100)*hpBarMax;
}
}
}