Fading out overlay in different map

Started by wizard_wizzle (aka ZeldaHistorian), December 13, 2015, 09:23:49 PM

Previous topic - Next topic
I have a surface that I'm using as an overlay, but it only exists on two maps. What I'd like to have happen is that when you enter one of the two maps, the overlay fades in (it's fog, so it's for effect) and then when you leave, it fades out. I can get the fade in to work just fine. I've tried to use the teletransport:on_activated event to call the fade_out, but so far I can't get it to work. I'm assuming the surface is automatically attached to the map because when you leave the map, the surface overlay immediately disappears. Is it possible to have this fade out instead?

I think it should work. Surfaces created by scripts are not attached to a particular object (unlike timers). Does it work correctly if you try that in a normal game sequence, I mean not during a map closing transition?
Do you show the surface from map:on_draw()?

Yeah, I show the surface from map:on_draw. Oh, I guess that's why it's not showing? Should I include the map:on_draw code in the adjacent maps as well?

Not sure what you mean by "try that in a normal game sequence"?

Sort of answered by own question - that worked!

I also noticed that if you fade in a surface and then change the opacity to something other than fully opaque, it goes all the way to opaque and back to the set opacity. Is there a way to correct the behavior, or would this be considered a later enhancement to the engine? I'm using the basic code below:


    if game.deception_fog_overlay then game.deception_fog_overlay:fade_in(150, function()
      game.deception_fog_overlay:set_opacity(168)
    end) end

December 14, 2015, 07:47:53 AM #4 Last Edit: December 14, 2015, 07:50:39 AM by Diarandor
Hi! I am not sure if this is what you want or if this is gonna work, but, maybe the solution is to set the opacity with
Code (Lua) Select
game.deception_fog_overlay:set_opacity(168)
just once (when you create the overlay, or maybe later), and not calling it from the fade-in callback. I suppose that the fade-in effect will start from transparent until it reaches the 168-opacity, but I am not sure at all (I have not tested this).
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

The effect of surface:fade-in() is to change the opacity gradually, so yes, calling surface:set_opacity() interferes with that. surface:fade_in() is equivalent to creating a timer that changes the opacity.

What I meant with "try that in a normal game sequence" is to try on a normally running map, not during a map transition, just to see if it works. So I guess it does :)

So okay, now I understand that you are trying to do that in a *scrolling* transition between adjacent maps. While you are scrolling, the new map exists (so it works), but the old map no longer exists (so the map:on_draw() of the old map is not called). If you still see the old map, it is only because the engine internally did a screenshot of the old map to be able to display it during the scrolling transition, but it is actually already destroyed. This is essentially an implementation detail though, it might change in the future to allow more advanced transitions.

A solution could probably be to show the effect from game:on_draw().

I had considered the game:on_draw method, but it seemed like overkill to me for just two maps. I ended up including map:on_draw code in the adjacent maps and the fade out now works.

So fade_in/out() doesn't take into effect the surface's opacity? Diarandor, I had tried to set the opacity when creating the surface in my first version of this code, but then it never reached the desires transparency - it faded in and remained fully opaque.

I guess I could just create my own timer that changes the opacity, and not use fade_in/out(), right?

Quote from: wrightmat on December 14, 2015, 02:08:52 PM
I ended up including map:on_draw code in the adjacent maps and the fade out now works.
It seems to be the good approach if it is only for two maps.

Quote from: wrightmat on December 14, 2015, 02:08:52 PM
I guess I could just create my own timer that changes the opacity, and not use fade_in/out(), right?
Exactly. fade_in/out() gradually set the opacity from 0 to 100 / from 100 to 0, so it ignores whatever opacity was set before.