我有一个用于健康条填充的矩形图像。当你的健康状况下降时,条形的宽度就会减小,直到你达到0。对于这部分代码,一切运行正常,条的宽度减小,并且当宽度改变时,它保持在相同的x位置。
我的问题是,当我创建具有不同HP值的怪物时,我会得到不同宽度的健康条。如何创建具有不同HP值的相同大小的矩形?非常感谢。
-- Create Health Bar
MonsterBar = display.newRect( 20, 160, 26, 10 )
MonsterBar:setReferencePoint(display.BottomLeftReferencePoint)
MonsterBar:setFillColor( 80,150, 0 )
-- Monster get hit
MonsterBar.width = MonsterBar.width - scoreHUD.text
MonsterBar:setReferencePoint(display.BottomLeftReferencePoint)
发布于 2014-04-24 23:31:15
您需要使用一个百分位中间值,然后可以在进度条中使用它。
例如,像这样计算一个超级健康百分比,确保HP Current为<= HP Max:
local nMonsterHPPercentile = (nMonsterHPCurrent / nMonsterHPMax) * 100
一旦你有了百分位数,调整你的矩形以创建最大尺寸为"100“(或200,300等,但你需要乘以怪物百分位数),并根据计算的百分位数显示各个矩形。例如,如果您的nMonsterHPPercentile为62%,而矩形的宽度为100,则执行一个循环,为每个10%的条形添加一个单独的hp矩形。
https://stackoverflow.com/questions/23257586
复制相似问题