ID:2264591
 
I've recently created a HUD bar system centered around Icon.Crop and I'd just like some advice on the effectiveness or lack thereof of this method, taking into account that I intend the world to be multiplayer.

mob
proc
updateHealth()
set waitfor=0
if(isplayer(src))
var/mob/M=src
if(M.ko)
if(M.HP>M.MaxHP*0.25)
M.UnHurt()
var/bars=round(M.baramt,1)
var/bar_on=1
var/percent=round((M.HP/M.MaxHP)*M.baramt,1)
if(percent>=bars)
percent=round(bars,1)
if(percent<=0) percent=1
healthnum(num2text(round(HP,1)))
var/sub=0
if(percent>100 && percent<=200)
sub=100
if(percent>200 && percent<=300)
sub=200
if(percent>300 && percent<=400)
sub=300
if(percent>400 && percent<=500)
sub=400
if(percent>500 && percent<=600)
sub=500
if(percent>600 && percent<=700)
sub=600
bar_on=(sub/100)+1
percent-=sub
percent*=1.6
for(var/obj/HMeters/o in hudobjs)
var/max=percent
if(o.bar_id>0)
if(bar_on>o.bar_id)
max=160
if(bar_on<o.bar_id)
max=0
max=160-max
baricon=new/icon(o.baseicon)
baricon.Crop(160,32,max,1)
o.icon=baricon
Please avoid icon procedures wherever possible.
Try looking into matrix with Scale(). You can accomplish the same thing you're attempting but with better performance and efficiency.
Ah, that was solution #1, but my hud bars are shaped like a stretched rhombus so the smaller the scale the more the sloped edges would lose their gradient, is there any direction you could point me in that would help with this or should I forget about style for now?
I don't believe there would be an issue using Scale() unless you wanted to specifically remove the slanted edge of the rhombus. You would want to use
atom/appearance_flags = PIXEL_SCALE

to keep it's visual crispyness otherwise it starts deforming the appearance.

"Normally if an icon is transformed via atom.transform, it uses bilinear texture sampling which produces a nice smooth effect. If you want a granular pixel-art effect instead, PIXEL_SCALE will do that for you. This flag is inherited by images and overlays. "

Oh, if you use matrix Scale() you'll need to use transform to re-align it in place.
I don't know if I'm doing it wrong then, but this is what i get with what I use

        size(s as num)
var/matrix/M=matrix()
animate(usr,transform=M.Scale(s,1))


hpbars

The first is the original, the second is 50% and the third is 5%