YesNoOk
avatar

Better method for Powerbars/Lifebars and etc. Var help (Read 1258 times)

Started by Plum, July 21, 2020, 05:54:30 am
Share this topic:
Better method for Powerbars/Lifebars and etc. Var help
#1  July 21, 2020, 05:54:30 am
  • **
  • Variables > Boyfriends
I can't really grasp how to "fill" and erase a powerbar using var(s) I used a method before; it was along the lines of "manually" slicing the bar and using a sprite for each one, but that took ages, and I've done it too many times now--I'd like to learn a better method. Recently I've seen characters that just have a full bar animation/sprite and they just have the bar... vanish or fill based on "root, var" or "numexplod" and I honestly can't wrap my head around it.

Example Below:


[State 8053, Filling Lv3 - P2]
type = Explod
triggerall = roundstate = 2
triggerall = (root,var(55)) >= 81
triggerall = (root,var(55)) < 120
triggerall = !numexplod(8053)
trigger1 = teamside = 2
anim = 8056
id = 8053
pos = (-(cond(numhelper(4000), helper(4000),var(56), 232)) + var(3) - 19), var(2)
postype = right
bindtime = -1
shadow = 0,0,0
ownpal = 1
scale = 1, 1
sprpriority = 4
ignorehitpause = 1

[State 8053, Modify]
type = ModifyExplod
triggerall = ishelper(8050)
trigger1 = numexplod(8053)
ID = 8053
scale = ((root,var(55)) - 80)/40.0, 1
ignorehitpause = 1
Re: Better method for Powerbars/Lifebars and etc. Var help
#2  July 28, 2020, 01:13:02 am
  • *****
  • Shame on you!
    • USA
So I'm not exactly sure which part of this you're having trouble with so I'll try to explain how it works in general.
You have your image you want to display as the actual power as the bar fills up.
That bar/image is a certain amount of pixels wide. Obviously you want it to be able to adjust it's width.
So to adjust a sprite's width we use
scale = 
And the width is going to change, but represent a certain Value. or for us, a Var.
scale = var(55), 1
would work. But that might not be the exact size we want. Because if the Var goes from 0 to 3,000, and we want our image to max out at, say 150 pixels wide, we need to scale the math properly.
scale = ((root,var(55)) - 80), 1
On top of that, Scale = doesn't work with pixels, it works with % of the original image. So
scale = ((root,var(55)) - 80)/40.0, 1
would be the best way to do it.

----
It's best if you figure out most of your math first, then make the image if you can. You may be able to make the math easier making the image a specific width to start with.
vVv Ryuko718 Updated 10/31/22 vVv
Last Edit: July 28, 2020, 01:16:11 am by Odb718
Re: Better method for Powerbars/Lifebars and etc. Var help
#3  August 08, 2020, 07:31:38 am
Take Sculd from cyberbots as an example.

Code:

;Launcher & counter

[State -2]
type = VarSet
trigger1 = 1
var(27) = 150                       ;reload time

[State -2]
type = Varadd
trigger1 = var(29) =1
v = 28
value = 1
ignorehitpause = 1

[State -2]
type = Varset
trigger1 = var(28) = var(27) ;150
var(29) = 0
ignorehitpause = 1

[State -2]
type = Varset
trigger1 = var(28) = var(27) ; 150
var(28) = 0
ignorehitpause = 1

[state -2]
type = Explod
trigger1 = numexplod(6000)<1
trigger1 = 1
;trigger1= teamside=1
anim = 6000                                                 ;power bar
ID = 6000
pos = 5 + 310*(teamside = 2),157 + 60
postype = left
facing = 1+(teamside = 2)*-2 ;1
;vfacing = 1
bindtime = -1
scale = 1,1
sprpriority = 9998
removetime=-1

[state -2]
type = Explod
triggerall = numexplod(6000) = 1
trigger1 = numexplod(6010) = 0
anim = 6010                                               ;power
postype = left
pos = 27 + 267*(teamside = 2),160 + 60
sprpriority = 9997
bindtime = -1
removetime = -1
supermove = 1
ownpal = 1
ignorehitpause = 1
removeongethit = 0
ID = 6010
facing = 1+(teamside = 2)*-2 ;1
scale = ifelse(var(29)=0,1.0,1.0*var(28)/var(27)),1       ;scaling math and variables

[state -2]
type = modifyexplod
trigger1 = 1
ID = 6010
scale = ifelse(var(29)=0,1.0,1.0*var(28)/var(27)),1      ;scaling math and variables
ignorehitpause = 1


His code is mean to restore the original size of his bar power after he loses it doing a laser attack.





He is able to do this by scalating the animation/sprite to a fraction of his size, doing maths with his vars in the "scale =" value of the explod. Them re-scalating at every moment with modifyexplod, updating it to match the rate in which his vars are fill. Even if doesn't seen like it the power animation sprite is of the exact size of his container and is just one sprite, that's the real size of the sprite when the var counter is completelly fillew if the equation is correct (scale = 1,1).







Another answers. "root," is a redirection that is apply to the trigger https://mugenguild.com/forum/topics/trigger-redirection-cns-168959.0.html. the code that you share maybe have another pieces of code that comes within, so unless you plan is doing the power bar with helpers you should no use it. Numexplod is just a trigger, you can replace it if doesn't match you idea of how the code might works.