Long topic title I know but I figured I share this with those who are looking for a decent code to fade a bg to black and fade back, make the bg stay black as long as you want then fade back to normal when ready.
Normally you can do such a thing with the palfx, bgpalfx, all palfx sctrls but you can't specify the amount of time to keep a bg a solid color before changing back which will result in everything happening in 1 shot.
With this formula I developed, you will have more control of the transition fading, speed of the fading, and time period of how long to keep that solid bg color before fading back to normal.
First you need to make a helper block to call for this BGPALFX helper to spawn.
[State 0, Background fx helper]
type = helper
trigger1 = time = 0
helpertype = Normal
id = xxxx
pos = 0,0
postype = p2
name = "BGFX"
stateno = xxxx
ignorehitpause = 1
persistent = 0
Place that block in whatever state of your character where you want this effect to kick in. Adjust the trigger to your likings also.
Now we have that helper block created we need to make the states for this.
Below I have everything set up and labeled areas where you can make your modifications:
;PalFX, BGPAlF, AllPAlFX Helper states
[statedef XXXX]
type = s
[State 0, AssertSpecial];Self Explanitory
type = AssertSpecial
trigger1 = 1
flag = invisible
flag2 = noshadow
[State 0, NotHitBy];Helper can't be attacked
type = NotHitBy
trigger1 = 1
value = SCA
[State 0, Offset]; Positions helper off screen
type = Offset
trigger1 = 1
y = 99999999
[State 0, VarSet]
type = VarSet
trigger1 = time = 0
v = 0
value = 256 ;leave as is
[State 0, VarAdd]
type = VarAdd
trigger1 = var(1) = 0
trigger1 = var(0) > 1;Do Not touch, this keeps the bg black after the fading!
v = 0
value = -1 ;decrease the value to speed the fade to black time, valid values are -1 through -5
[State 0, VarSet]; BG is now completely black, Do not alter this block
type = VarSet
trigger1 = var(0) < 2
v = 1
value = 1
[State 0, VarAdd]
type = VarAdd
trigger1 = var(1) = 1
trigger1 = var(0) <= 256;leave as is
trigger1 = time > 400 ;adjust to your likings, decrease or increase time variation to fade back to normal
v = 0
value = 1 ;increase the value to speed the fade to normal time, valid values are 1 through 5
[State 0, BGPalFX]
type = BGPalFX
trigger1 = var(0)
time = 1
add = 0,0,0
mul = var(0),var(0),var(0)
sinadd = 0,0,0,10
invertall = 0
color = 256
[State 0, DestroySelf]
type = DestroySelf
trigger1 = time > 10
trigger1 = var(0) >= 256
This uses the two vars I created in the helper, (by the way that part of the code can be copied and pasted but you still have to make adjustments to match your satisfaction and helpers uses their own vars so they can be left as it), are set to play as the identifiers in the BGPalFX sctrl block. whatever changes the vars makes, the BGPalFX scrtl will read them and match the changes made. Pay attention to everything I labeled in the code for better understanding.
*Note: when adjusting the values in the varadd sctrls, values that are higher or lower that the prefered values may still work but will result in debug flooding or the entire trick not to act properly. The max allowed values should be fast enough. Also the lines XXXX, change them into numeric values and make sure they all are the same.