Wintermute Engine Forum
Wintermute Engine => Technical forum => Topic started by: TheDerman on December 09, 2005, 02:31:28 AM
-
Hi,
Just wondering how I can fade the inventory window in and out. I have it at the bottom of the screen, and when the player moves the mouse down there I want the window to fade in (I'm assuming all the items will fade in aswell if the actual window is set to fade). Then when they leave that area, the window fades out.
Where can I put the necessary code?
Thanks.
-
It's mostly a matter of convenience. Personally, I'd create two methods, FadeIn() and FadeOut() and place them to the script attached to your inventory window. Something like:
method FadeIn()
{
// some fade in code similar to what you're using to fade in the actor
// http://forum.dead-code.org/index.php?topic=936.msg6969#msg6969
}
Then you'd have to modify the game_daemon.script, which handles the inventory display/hide.
Right now it does something like: Game.InventoryVisible = true;
You'd have to replace this line by something like:
var InvWindow = Game.GetInventoryWindow();
InvWindow.FadeIn();
I hope that makes sense. If not, feel free to ask for further details :)
-
Was I really fading in the actor? How crazy of me - I'm not doing that anymore. ;D Actually, it's a different game.
Thanks for the help - I'll give it a try.
EDIT - had another question here, but I sorted it out. 8)
-
Ok, I'm afraid I don't really understand how to do this inventory fading thing.
I put the method code in my inventory.script? But then after I put all the fading stuff, what do I actually tell it to fade?
This is how I'm fading stuff:
for(var i=1; i<=10; i=i+1)
etc...
But don't I need to actually state what is I'm fading after that code? ???
I need mucho more help. Cheers.
-
You put the two methods to the script attached to the inventory window. In your inventory box defintion there's something like:
INVENTORY_BOX
{
ITEM_WIDTH = 65
ITEM_HEIGHT = 65
blah blah
...
WINDOW
{
blah blah
...
You need to attach the script to the embedded window like this:
INVENTORY_BOX
{
ITEM_WIDTH = 65
ITEM_HEIGHT = 65
blah blah
WINDOW
{
SCRIPT = "path\window_fading.script"
blah blah
...
And those two methods will look exactly like the actor fading code in the other thread linked above, but you'll replace "actor" with "this". Since the script is attached to the inventory window, the "this" variable points to the window itself.
I hope that helps.
-
I tried all that you suggest but it still won't fade in - I just get nothing, no inventory.
This is my inventory.script attached to the inventory.def
#include "scripts\base.inc"
method FadeIn()
{
for(var i=1; i<=10; i=i+1)
{
this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
Sleep(100);
}
this.AlphaColor = MakeRGBA(255, 255, 255, 255);
}
method FadeOut()
{
for(var i=10; i>=10; i=i-1)
{
this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
Sleep(100);
}
this.AlphaColor = MakeRGBA(255, 255, 255, 0);
}
This is my game_daemon.script
// display the inventory window
var InvWindow = Game.GetInventoryWindow();
if(Game.Interactive && Game.MouseY > 704 && !Game.ResponsesVisible && !WinMenu.Visible)
{
InvWindow.FadeIn();
}
else if(Game.MouseY < 704 || Game.ResponsesVisible || !Game.Interactive)
{
InvWindow.FadeOut();
}
But it doesn't work. ???
-
Ok, one more thing you'll probably have to do, this.Visible = true; at the beginning of FadeIn, and this.Visible = false; at the end of FadeOut. That should do the trick, I hope...?
-
Nope. I'm afraid that didn't work either. ;D
Tough one eh?
-
Ok, I replaced your this.Visible = true; with Game.InventoryVisible = true; at the start of FadeIn and Game.InventoryVisible = false; at the end of FadeOut.
Now the inventory continuously fades in and in and in and in forever. And just disappears when I move the mouse out of the area, so I guess the fade in is working somewhat but the fadeout not at all...???
;D
EDIT - could this be due to the game_daemon.script looping? So everytime that script loops around, and the conditions for fading in the inventory are TRUE (i.e. my mouse is at the bottom of the screen), it's fading in the inventory again and again...???
-
yes, you should put there condition to fadein or out only if it's not been faded already.
-
Thanks Metamorphium, I guessed that - took me a bit to figue it out how to put that condition in there though. ;D
But I now have a perfectly fading inventory - yay!!! Just need to adjust the speed now.
Here's the code I ended up with in case anyone else comes looking.
inventory.script
#include "scripts\base.inc"
global Faded;
method FadeIn()
{
Game.InventoryVisible = true;
for(var i=1; i<=10; i=i+1)
{
this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
Sleep(100);
}
this.AlphaColor = MakeRGBA(255, 255, 255, 255);
Faded = true;
}
method FadeOut()
{
for(var i=10; i>=1; i=i-1)
{
this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
Sleep(100);
}
this.AlphaColor = MakeRGBA(255, 255, 255, 0);
Game.InventoryVisible = false;
Faded = false;
}
and the game_daemon.script
// display the inventory window
var InvWindow = Game.GetInventoryWindow();
if(Game.Interactive && Game.MouseY > 704 && !Game.ResponsesVisible && !WinMenu.Visible && Faded ==false)
{
InvWindow.FadeIn();
}
else if(Game.MouseY < 704 || Game.ResponsesVisible || !Game.Interactive)
{
InvWindow.FadeOut();
}
And I had to put global Faded = false; at the top of the game_daemon.script (I think - well I did anyway and it works ;D).
Thanks guys - I'm very happy now. ::rock
-
This can't work IMO properly. Try to fade it out and then quickly move your cursor up and down. You will probably see another fadeout.
I would recommend trying something like this:
method FadeIn()
{
... // the code from your function as-is
Faded = true;
}
method FadeOut()
{
... // the code from your function as-is
Faded = false;
}
// the conditions should be something like
if (!Faded) InvWindow.FadeIn();
//And
if (Faded) InvWindow.FadeOut();
It's of course untested, but should work anyway. ;)
-
It works perfectly with the code I stated as far as the fade in and out goes.
Only problem was that it was continuously running the fadeout code when the inventory was not visible. That didn't affect the fade in or out, but it did slow down my caption window a little, but I fixed that with another condition so no problems here. 8)
Thanks again.
-
Hi there,
Is there any chance oyu could put the full scripts for this and how to achieve this somewhere on the forum.
I would like to have a go at fading in/out my inventory box and maybe other windows??
If not then maybe you can send me the scripts via email and how to achieve this.
(Been trying to do this for ages!! hahahahahahahahahahaha)
-
I have found this thread and it is great :)!!! Very thx to all! :)
-
I am having trouble with this, I have used the scripts listed but the inventory does not show at all now.
I have connected it to my INVENTORY window script.
Updated Game Deamon but still nothing.
Any help or full scripts would be good, save my hair being pulled out. hahahahahahaha
-
These are the scripts I have:
inventory.script:
#include "scripts\base.inc"
global Faded;
method FadeIn()
{
Game.InventoryVisible = true;
for(var i=1; i<=10; i=i+1)
{
this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
Sleep(40);
}
this.AlphaColor = MakeRGBA(255, 255, 255, 255);
Faded = true;
}
method FadeOut()
{
for(var i=10; i>=1; i=i-1)
{
this.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
Sleep(40);
}
this.AlphaColor = MakeRGBA(255, 255, 255, 0);
Game.InventoryVisible = false;
Faded = false;
}
And the relevant section of the game_daemon.script:
// display the inventory window
var InvWindow = Game.GetInventoryWindow();
if(Game.Interactive && Game.MouseY > 704 && !Game.ResponsesVisible && !WinMenu.Visible && Faded==false)
{
InvWindow.FadeIn();
}
else if(Game.MouseY < 704 && Faded==true)
{
InvWindow.FadeOut();
}
Hope that helps.
-
Many thanks TheDerman.
In the game deamon scripts does this new code replace the old (unchanged demo script) or does it need to be added with the old code??
Cheers
-
It replaces only the part of the daemon script which deals with the inventory (down at the bottom) - everything else should be left as it is.
You will have to change certain things specific to your game, like the Y value - my inventory is at the bottom of the screen - you may have yours at the top or somewhere else.
-
ok many thanks, will give it a bash and let you know.
-
Hi,
I have tried to implement these scripts but my inventory does not show.
I have attached the inventory fade script to my inventory window and changed Game Deamon script but still no inventory is showing.
TheDerman can you show me your full Game Deamon script on this thread as I think that is the issue here.
Cheers
-
Hi SBOVIS :)!
Did you create a global Faded = false; in your game_daemon.script?
-
Certainly did, still no show on my inventory though, If I take the fade code out and reset it back the way it was, I get the inventory no problem. (just not fadeing)
-
Maybe if you post your inventory script and daemon script, we could spot the problem?
Did you insert SCRIPT = "interface\inventory.script" into your inventory.def in the WINDOW section of the file?
-
Also please check your wme.log for error messages. You'll usually find some clues as why it doesn't work there. If there is something written what looks like an error, post it together with requested files too. ;)
-
ok will check and post files if needed.
many thanks
cheers
-
Got this to work now, many thanks, looks great,
It was the Game.Deamon script as I have other code that conflicted with it.
By the way can this fade method be used for any windows??
I have several that would work well when faded, I have defined windows so do I do a similar script and attach it and call that within other scripts when I want it to fade??
Seems feasible??
-
yes, you can definitely use it for any window you like.
Glad it works for you now.
-
i think, that you can optimize it and skip needlessly tests in game_daemon.script...
inventory.script:
#include "scripts\base.inc"
global Faded;
method FadeIn()
{
if(!Faded) {
Game.InventoryVisible = true;
for(var i = 0; i <= 255; i = i + 25) {
this.AlphaColor = MakeRGBA(255, 255, 255, i);
Sleep(40);
}
this.AlphaColor = MakeRGBA(255, 255, 255, 255);
Faded = true;
}
}
method FadeOut()
{
if(Faded) {
for(var i = 255; i >= 0; i = i - 25) {
this.AlphaColor = MakeRGBA(255, 255, 255, i);
Sleep(40);
}
this.AlphaColor = MakeRGBA(255, 255, 255, 0);
Game.InventoryVisible = false;
Faded = false;
}
}
-
This is cool, I now have an inventory and other windows fadeing in and out, many thanks.