DIY fade out using transparency [SOLVED]

Started by Phonoitypal, Thu 27/07/2023 21:49:12

Previous topic - Next topic

Phonoitypal

Hello !
This is my second day of using AGS.
I'm working on some game, so far - so good, I'm reading the documentation and I got a 'hang of it' - managed to do my first animation in the engine etc.
But I encountered a problem, which I think, in it's essence, might be simple, but I honestly lack the understanding as how to do it.

The idea : I want to make my own 'fade in' as in an object that is completely black, that decreases its transparancey over time so that it reaches 100(invisible); The question that I'm about to ask has to do with my stupid way of implementing it so that it does not work. Anyways, this question will also help me in the future regarding object transition of transparency and so on. I think I got lost a bit in the detail.

THE PROBLEM :
Whenever I'm trying to use the provided documentation regarding transparency
Code: ags
int trans = object[0].Transparency;
while (trans < 100) {
    trans++;
    object[0].Transparency = trans;
    Wait(1);
}

I get the error that after the "= of trans" the 'engine' expects an integer value.

What I did, so far, to test, was this

Code: ags
function room_Load() {
oBlack1.Transparency = 0; //Visible
}
if I try to put it in the room_Load stuff, it would not work, so I followed this example provided here:
Code: ags
function room_Load() {
  object[?].Transparency = 100; // Make full screen Object invisible.
}
followed by

Code: ags

// BEGIN FADING IN FULL SCREEN OBJECT SCRIPT.
        //-------------------------------------------
        int trans = object[?].Transparency; // Fade in the full screen Object until it is visible. 
        while (trans > 0) {
        trans--;
        object[?].Transparency = trans;
        Wait(1);
        }
        // END OF FADE IN SCRIPT.
        //-----------------------




Following this example step by step, replacing the object[?] - with my case, oBlack1 etc, does not work and always gives an unexpected 'while' or the engine crashes.
What am I doing wrong ? Could someone shed light as what I am missing ?

Thanks in advance and I really hope im not wasting your time !

Phonoitypal

Also I hope my broken english at least allowed me to explain what I'm trying to achieve =(

Phonoitypal

Hey ! I managed to make my own FADE IN
using a guy with this code
Code: ags
function room_Load() {
gBlack1.Visible = true;
FadeOut(64);
oSky1.SetView(VSKY);
oSky1.Animate(0, 20, eRepeat,  eNoBlock);
}

function room_AfterFadeIn() {
  FadeOut(64);
  gBlack1.Visible = false;
  Wait(1);
  FadeIn(1);
}







- the vsky should be ignored since it does not have anything to do with my problem.
The thing is, how can I make it so that the 'fade out' effect is not as fluid ? I want to make it in a way so that it shows 2 levels of transparency (half, and completely transparent) successible, like on those old 8-bit games, the 'transition' has very low fps. Anyone can help me with that ?

Khris

Your original problem is that you put that code directly into the room script, as opposed to inside a function.
AGS is event-based, so whatever you do, whether it's interact with something, enter a room, click a GUI button, etc. you can associate a function with this event, then put appropriate code inside that function.

AGS complains because while you can in fact use a line like
Code: ags
int trans = 0;
outside a function (this will create a room variable and initialize it to zero) only constant values are allowed here, so your line caused an error.

The main question you need to ask yourself is: *when* do you want that code to run? Fading out an object presumable happens after the player has interacted with something, so you need to create and link the event function as explained in the manual's tutorial, then put the code inside the new function.

Phonoitypal

Yes you are right !

Thank you so much for the reply.
Regardless, I managed to do this myself, by using 2 kind of GUI's , one that is transparent 50% and one that is fully invisible, just like this :

Code: ags

function room_Load() {
oSky1.SetView(VSKY);
oSky1.Animate(0, 20, eRepeat,  eNoBlock);
}

function room_AfterFadeIn() {
  Wait(20);
  gBlack1.Visible = false;
  Wait(20);
  gBlack2.Visible =false;
}



The problem that I'm encountering now is while this all happens, the 'animation' that I set up in my background (via the vSky stuff) pauses untill the fade out effect is finished. Is there a workaround against this ?

Phonoitypal

Nevermind, after a re=run it seems like I was not paying attention and actually they did not stop. thanks for your answer, I think this is solved.

SMF spam blocked by CleanTalk