Is there a way to make a single background frame fade in? [SOLVED]

Started by RetroJay, Sat 10/01/2015 01:12:24

Previous topic - Next topic

RetroJay

Hi Peeps.

What I would like to try and accomplish should be fairly simple... I think.
The only problem I have is that I don't know the best way to do it.

A certain room, in my game, the background is in a dilapidated state but by using some magic everything becomes shiny and new.
I have done this by creating one other background frame and assigning it when the magic happens...But.
Is there a way of making this transition fade-in instead of just... Boom! there ya go.(laugh)

Am I going about this the right way or is there a better way?

Yours.
Jay. 

Cassiebsg

Am sure you can code it using transparency settings (try doing a search for it, as it's been answered not so long ago). You probably need one of the "backgrounds" to be an object sprite.

There are those who believe that life here began out there...

Adeel

Did you try using FadeIn and FadeOut to achieve the smooth transition? FadeOut the screen, set the background frame, and then FadeIn. I've not tried this so I can't say with assurance whether it will work or not. But I say, give it a shot, eh? :smiley:

Mandle

Quote from: Cassiebsg on Sat 10/01/2015 09:52:12
Am sure you can code it using transparency settings (try doing a search for it, as it's been answered not so long ago). You probably need one of the "backgrounds" to be an object sprite.

I think Cassie is right. The "shiny new" background should be a screen-sized object set on Visible = false; and Transparency = 100; and with a baseline set at 0. Then you just turn it visible, and start reducing the transparency in steps of 5 or 10 or whatever depending on how smooth you want the transition to be, until it hits zero. Oh, and the object must have no clickable interactions of course.

I think this should work.

RetroJay

Hi Guys.

Sorry it's taken me a while to reply.
I haven't had access to a computer over the Weekend.:(

Cassiebsg and Mandle.
Thank you. I was going to do it with a full screen object but just wondered if I could have used a background frame instead.
Mind you I think doing it the object way I might even be able to get a nice animating effect to work as it fades in. (so long as it doesn't affect game performance.):-\
I will just have to test it and see what happens.

Adeel S. Ahmed.
Thank you. I tried what you suggested but strangely AGS totally ignores the 'SetBackground' part and just fades out and back in.
I thought, after trying it though, that the effect wouldn't be much different then just creating another room to change to.
This maybe the path I will choose if all else fails.
At least I could set up other interactions, if I decide to.

EDIT:
I have just found this little gem.
Code: ags
1.SetNextScreenTransition(eTransitionInstant); 

Ok. Bear with me on this...
If I used a full screen Object and faded it in then after the fadein script used the line above then change room.
I think I may get just what I'm looking for... I think.
Also I could then set interactions, if I want, because it would obviously be a new room.
I'll let you know if it works, when I get around to trying it.(roll)

Thank you all for your help, it is much appreciated.

Yours.
Jay.


Slasher

As a matter of interest,

Is the room change the background only or are there objects that change?

If they are objects that you want to change, are there many?

There could be a better way.

RetroJay

Hi Slasher.

Sorry to take so long in replying, things are a bit hectic at the moment.

Yes, I only want to change the background but wanted the changed background to fade in gradually.
Once the background has finished fading in I would then change room instantly because then I could make new objects etc.

In the manual it says this.
QuoteIn order to fade an object in/out, the best approach is shown in the example below:

Example:

int trans = object[0].Transparency;
while (trans < 100) {
  trans++;
  object[0].Transparency = trans;
  Wait(1);
}

will gradually fade out the object from its current transparency level to being fully invisible.

This is very nice but I can't get it to work, my full screen background object won't fade in or out.???

Edit:
If someone could just point me in the right direction of how to fade an object in from totally transparent then I could work the rest out by myself.

Yours.
Jay.

RetroJay

Hi All.

Don't worry, I have just sorted it out.:-D
I did it this way
Code: ags
int trans = object[0].Transparency;
while (trans > 0) {
  trans--;
  object[0].Transparency = trans;
  Wait(1);
}


Now it works beautifully.

Edit...Again.:P
I will show you how I got the result I wanted.
I noticed whilst trawling through the search that a lot of people seem to have problems with transparency so this may help.
Where object is [?] the question mark is to be replaced with your object number.

1. I started by creating a full screen Object of my changed background. (You may have to mess about with the objects Baseline depending on where other objects are on screen.)
2. within my room script I put this.
Code: ags
function room_Load() {
  object[?].Transparency = 100; // Make full screen Object invisible.
}

3. Then within the function where I want the fade-in to happen I put this.
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.
        //-----------------------
        SetNextScreenTransition(eTransitionInstant); // Change room instantly with no black.
        cEgo.ChangeRoom(?); // Change ? to your next room.
      }
 
4. The next room will have its main background picture which is the same as the full screen Object we used in the last room.
   Use the same full screen Object for our new room and in our new rooms script put this.
Code: ags
function room_FirstLoad() {
  object[?].Transparency = 0; // Makes the full screen Object visible the first time Player enters room.
  // BEGIN FADING OUT FULL SCREEN OBJECT.
  //-------------------------------------
  int trans = object[?].Transparency; // Gradualy fade out the full screen Object until it is totaly invisible.
  while (trans < 100) {
  trans++;
  object[?].Transparency = trans;
  Wait(1);
  }
  // END OF FADING OUT SCRIPT.
  //--------------------------
}


I went for a white fade-in and out to the new room, in the end, because it better suited what I wanted but...
If you are using an object that is the same as the next rooms background then you can do away with step 4.

I think that this is a rather nice little effect and I hope that this helps someone else. 

Thank you all for your help on this matter.

Yours.
Jay.

Mandle

So...does this mean we are finally going to get to find out what is on the other side of that dark forest?! Please say yes!!! Pleeeeeaaaassse...

RetroJay

Hi Mandle.

Let me see... Umm... Hmm... Ohh... Alright then... Yes! (laugh)

Glad to see that you are keen to find out what happens to our Hero.(nod)
I still have a shed load of work to do on it, though.
I am only one man doing everything (art, scripting etc.)
However I do have many people telling me what they want me to put in it.(roll)

The effect that I have sorted is actually for another game I have been making.
A kind of chill project from my main one, if you like.
Hopefully I will post something on the GIP thread soon.

Yours.
Jay.

Cassiebsg

Glad you got it sorted out and thanks for posting the "solution"... Had I known about this command when I did Minifeg, I would have used it instead of making transparent sprites for my time machine fade in/out... (laugh)
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk