Pulsating opacity on a layer?

Hey! I have a lights layer in my map that I want to change the opacity - to imitate a light flicker. I have successfully done it with a parallel event - the effect is very cool, highly recommend it!

upload_2019-11-28_22-5-4.png


The only problem with this is the event pauses whenever a text window opens (so pretty often). Is there a way to do it completely in the background?

Some of my maps have 3 times of day with different lighting so the script would have to allow for changing that based on a switch or something.

How hard would that be to pull off?
Not sure why the event stops every time there's a message window. Don't events just keep doing their own thing?

I would put the first two commands on a single event, that runs when you enter the map then erases itself. Everything else I'd put into a second event, set to parallel process, and get rid of the Loop. Also put the Wait 1 Frame in there just once, at the very top of the event.

Parallel process events should continue, even when there's a message window open. Unless you've added a plugin that changes that behaviour.
I could get rid of the outer loop, but it would still not get rid of the 2 inner loops. I'll test it and see how it behaves, but I don't know if that will change much.
Aaaand I was wrong. The event is actually much more complex than just those 2 lines outside it (it was a snippet) but I'll break it into a bunch of events and it should work. Thank you!
You should only need two - one that runs just once on entering the map, and one that runs continually while on the map. Neither of them require loops. Loops together with parallel process events DO cause problems.

If you'd like to post the entire event, I can give you a hand with it. I think we can make it more simple than you have there.
How do you want to make a loop of changing the opacity by 1 between 150 and 255 and back without a loop? 🙂
A parallel process does not need a loop, as it loops automatically 🙂 The important thing is getting all the stuff you want done only once into one event, and all the stuff you want to repeat into another, so you can avoid adding loops inside the already-repeating event.

Your first event:
Code:
Control Variables #55 = $gameMap.layerSettings[35][3].opacity
Control Variables #56 (Light Adjustment) = 1
Fadein Screen
Erase Event

Your second event:
Code:
Wait 1 Frame
If Variable #55 >= 255
  Control Variables #56 = -1
Else
  If Variable #55 <= 150
    control Variables #56 = 1
  End
End
Control Variables #55 += Variable #56
Plugin Command: LAYER_S 35 3 Inn_light_night 0 0 v55 6 0 0 0

The above will replace everything in your event from the first Loop statement to its corresponding Repeat Above. Variable 56 just says whether opacity is going to increase or decrease, and when it hits one of your magic numbers, it reverses polarity.

Both events are set to parallel process.

Now you didn't include whatever happens outside of that main loop, or what happens after the If Light Animation = 150 test, so I can't guess at what the other stuff is. It may be that it needs to happen in another event, but maybe not. Care to share?
Yep, didn't think to do it this way, you are right.

The "other stuff" checks for the time of day (day/evening/night), sets different parallax layers and then based on that fades the opacity of different layers.

But yeah, should be enough to have 2 events, just with nested ifs. Or one event for setting the correct layer and then erasing itself and the other for all the opacity control. Or just to split up the opacity controls into 3 (or rather 3 pages) triggered by the time of day switches.
Yeah, the other stuff could just be added to the same event, so it does a wait, animates the lights, sets the layer opacity depending on time of day. With that one though, if it's not changing the opacity every single time, you might be better off having an additional switch turn on ONLY when it changes from one time of day to another, so you can do the opacity stuff once then turn off the switch, then not have to do it again until it needs to be done. This is more efficient than doing a number of tests to see what time of day it is, then changing the opacity accordingly, when the opacity was already set correctly.

Have fun 🙂

Original thread: https://forums.rpgmakerweb.com/threads/pulsating-opacity-on-a-layer.115735/