HealthBar Actionscript

发布于 2025-01-25 16:39:30 字数 387 浏览 3 评论 0原文

这是我对Healthbar这个问题的回答:

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();
}

Here's my answer to this question for the healthbar:

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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2025-02-01 16:39:30

问题:“当乒乓球撞击障碍时,HealthBar正在减少。”

解决方案:您需要使用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;
}

Problem: "When the pong hits the barrier, the healthbar is decreasing."

Solution: You need to use HitTesting. Use EnterFrame to check "hits" every moment.

Try this code setup.

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文