HealthBar Actionscript



我对健康栏这个问题的回答是:

function HealthBar() {
var percentHP = currentRaidBossHP / maxRaidBossHP
RaidBoss_HealthBar.barColor.scaleX = percentHP;
}
function BarrierHitted(): void {
currentRaidBossHP -= Math.floor(Math.random() * 100001);
if (currentRaidBossHP <= 0)
{
percentageHP_txt.visible = false;
}
HealthBar();
}

问题:"当pong击中障碍物时,生命条正在减少">

<<p>

解决方案/strong>你需要使用HitTesting。使用EnterFrame检查"命中"。每一刻。试试这个代码设置。

var RaidLives :uint = 3;
var maxRaidBossHP :uint = 5000;
var currentRaidBossHP :int = maxRaidBossHP;
var percentRaidBossHP :Number  = -1.0; 

//# use an EnterFrame function to check for collision
//# EnterFrame runs EVERY frame-per-second (FPS)
//# if FPS is 30 then EnterFrame checks 30 times for every 1 second
stage.addEventListener( Event.ENTER_FRAME, check_for_Collision );
function check_for_Collision (evt :Event) 
{
if ( ( ProtodermisEntity.LifeAura.hitTestObject(blowfishPong) ) == true ) 
{
trace( ">> Barrier was collided ... " )

//# test without using IF statement
BarrierHitted();
updateTextFieldsSecret();

//# Dont know if this code below works or not
//# use it after testing without IF...

/*
if (ballSpeedXSecret > 0) 
{
ballSpeedXSecret *= -1;
ballSpeedYSecret = calculateBallAngleSecret(ProtodermisEntity.y, blowfishPong.y);

BarrierHitted();
updateTextFieldsSecret();
}
*/
}
}
function BarrierHitted(): void 
{
currentRaidBossHP -= 10;

if (currentRaidBossHP <= 0)
{
ProtodermisEntity.gotoAndStop(6);
if(ProtodermisEntity.Stunned == 110)
{
stage.removeEventListener(Event.ENTER_FRAME, loopSecret);

sound_channel.stop();

//# bad idea to move Stage to another frame, good luck with future problems
//# should be... someMC.gotoAndStop (where someMC has frame label "gameover_Secret")
gotoAndStop("gameover_Secret"); 

//# cannot return anything if you got "void" setting for  your function
//return;
}
}

//# update gauge or health, because barrier was hit.
updateHealthBar();
}
function updateHealthBar(): void 
{
percentRaidBossHP = currentRaidBossHP / maxRaidBossHP;
RaidBoss_HealthBar.barColor.scaleX = percentRaidBossHP;
}

最新更新