Jibble

Author Topic: Is there a way to make a single background frame fade in? [SOLVED]  (Read 1042 times)

RetroJay

  • Posts: 537
  • Frankly, my dear, I'm a Kerbal and Proud of it.
    • RetroJay worked on a game that was nominated for an AGS Award!
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. 
« Last Edit: 14 Jan 2015, 00:35 by RetroJay »
  Master Decorator

Cassiebsg

  • Cavefish
  • Posts: 5,013
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
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

  • Cavefish
  • Posts: 1,519
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

  • Posts: 7,891
  • NO PIXEL LEFT BEHIND!!!
    • Mandle worked on a game that was nominated for an AGS Award!
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

  • Posts: 537
  • Frankly, my dear, I'm a Kerbal and Proud of it.
    • RetroJay worked on a game that was nominated for an AGS Award!
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: Adventure Game Studio
  1. 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.

« Last Edit: 12 Jan 2015, 07:03 by RetroJay »
  Master Decorator

Slasher

  • Posts: 2,756
  • slasher
    • I can help with AGS tutoring
    • Lifetime Achievement Award Winner
    • I can help with scripting
    • I can help with story design
    • Slasher worked on a game that was nominated for an AGS Award!
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.
« Last Edit: 12 Jan 2015, 16:41 by slasher »

RetroJay

  • Posts: 537
  • Frankly, my dear, I'm a Kerbal and Proud of it.
    • RetroJay worked on a game that was nominated for an AGS Award!
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.
Quote
In 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.
« Last Edit: 13 Jan 2015, 22:08 by RetroJay »
  Master Decorator

RetroJay

  • Posts: 537
  • Frankly, my dear, I'm a Kerbal and Proud of it.
    • RetroJay worked on a game that was nominated for an AGS Award!
Hi All.

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

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: Adventure Game Studio
  1. function room_Load() {
  2.   object[?].Transparency = 100; // Make full screen Object invisible.
  3. }
3. Then within the function where I want the fade-in to happen I put this.
Code: Adventure Game Studio
  1.         // BEGIN FADING IN FULL SCREEN OBJECT SCRIPT.
  2.         //-------------------------------------------
  3.         int trans = object[?].Transparency; // Fade in the full screen Object until it is visible.
  4.         while (trans > 0) {
  5.         trans--;
  6.         object[?].Transparency = trans;
  7.         Wait(1);
  8.         }
  9.         // END OF FADE IN SCRIPT.
  10.         //-----------------------
  11.         SetNextScreenTransition(eTransitionInstant); // Change room instantly with no black.
  12.         cEgo.ChangeRoom(?); // Change ? to your next room.
  13.       }
 
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: Adventure Game Studio
  1. function room_FirstLoad() {
  2.   object[?].Transparency = 0; // Makes the full screen Object visible the first time Player enters room.
  3.   // BEGIN FADING OUT FULL SCREEN OBJECT.
  4.   //-------------------------------------
  5.   int trans = object[?].Transparency; // Gradualy fade out the full screen Object until it is totaly invisible.
  6.   while (trans < 100) {
  7.   trans++;
  8.   object[?].Transparency = trans;
  9.   Wait(1);
  10.   }
  11.   // END OF FADING OUT SCRIPT.
  12.   //--------------------------
  13. }

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.
« Last Edit: 14 Jan 2015, 00:34 by RetroJay »
  Master Decorator

Mandle

  • Posts: 7,891
  • NO PIXEL LEFT BEHIND!!!
    • Mandle worked on a game that was nominated for an AGS Award!
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

  • Posts: 537
  • Frankly, my dear, I'm a Kerbal and Proud of it.
    • RetroJay worked on a game that was nominated for an AGS Award!
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.
  Master Decorator

Cassiebsg

  • Cavefish
  • Posts: 5,013
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
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...