Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rex Mundane on Fri 22/01/2010 06:57:00

Title: Animating GUI Inventory Bar, is there another way?
Post by: Rex Mundane on Fri 22/01/2010 06:57:00
So the idea is that I want a bar at the bottom of the screen with the inventory in it that appears and disappears off the bottom of the screen whenever the mouse is on it, like in Broken Sword frinstance. What I've got is basically a little script in the repeatedly_execute() function that reads as follows: if (mouse.y > 549) {
    if (gInv.Y > 549) {
      gInv.Visible = true;
      gInv.Y-=5;
    } else {
      gInv.Y = 549;
    }
  } else {
    if (gInv.Y < 599) {
      gInv.Y+=5;
    } else {
      gInv.Y = 599;
      gInv.Visible = false;
    }
  }


(For clarification, the game is in 800x600 resolution)

Now this works fine, but seems... I dunno, unnecessarily absurd to me? Is Inelegant the word I'm looking for? Anyway it seems to me (and bear in mind I am an imbecile) that there just has to be a better way than this to accomplish something as simple as this, and I just wanted to ask, is there?
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Goldfish on Fri 22/01/2010 08:08:41
Am I missing something? (probably) :) but wouldn't you just set where you wanted the GUI then in its properties change it so that it appears on mouseover, then set the Y coordinate to your liking?

Please forgive me if I have missed the point.
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Khris on Fri 22/01/2010 10:36:09
Well, AGS has built-in functionality for showing a GUI at the top of the screen; scrolling it in at the bottom has to be done manually, indeed.
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Goldfish on Fri 22/01/2010 10:48:56
So...

game start

gui.visible=false


then

(y coordinate of mouse > value say 500){
   gui.visible=true
   etc. etc.
}

(y coordinate of mouse < 501{
   gui.visible=false
   etc.etc.
}

?

Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Rex Mundane on Fri 22/01/2010 16:41:20
Well no, yeah that gets it to appear and disappear, not just putting it at the bottom but specifically I was hoping to be able to get it to scroll up and down visibly instead of just *snap* there it is. What I've got works, but it just, I dunno, feels like I've done something the hard way that must be simpler than I'm thinking.
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Crimson Wizard on Sat 23/01/2010 16:20:58
I don't see anything stupid in this code; even if there's some trick in AGS that you (and me ;)) doesn't know, well, what the heck!
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Matti on Sat 23/01/2010 16:36:19

if (mouse.y > 500){
   if (gui.visible==false) gui.visible=true;
   if (gui.y>500) gui.y--;
}

if (mouse.y < 501 && gui.visible){
   if (gui.y==600) gui.visible=false;
   else gui.y++;
}

Something like this should work. Of course you have to alter the values. In this example the gui is 100 px high at a resolution of 800x600.
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Calin Leafshade on Sat 23/01/2010 16:41:40
The best way to do this is to have a boolean which is checked in rep ex but have the movement code in rep ex always.

This means the gui wont detect its supposed to move during blocking functions but it will still move during block functions.

a rather poor, uncommented example from a game I'm working on. (which actually has all the code in rep ex always and i use the bool 'blocking' to detect blocking functions



 
 if (mouse.Mode != eModeInteract){
 if (mouse.y < 5 && gInventory.Y < 0 && !blocking){
   MoveGuiDown = true;
   MoveGuiUp = false;
 }
 if (mouse.y > 40 && gInventory.Y > -40 || blocking){
   MoveGuiDown = false;
   MoveGuiUp = true;
 }
 }
 
int GuiMoveSpeed;

 if (MoveGuiDown){
   if (gInventory.Y < -30) GuiMoveSpeed = 4;
   else if (gInventory.Y < -25) GuiMoveSpeed = 3;
   else if (gInventory.Y < -10) GuiMoveSpeed = 2;
   else if (gInventory.Y < 0) GuiMoveSpeed = 1;
   gInventory.Y += GuiMoveSpeed;
   if (gInventory.Y == 0) MoveGuiDown = false;
 }
 if (MoveGuiUp){
   if (gInventory.Y > -10) GuiMoveSpeed = -4;
   else if (gInventory.Y > -20) GuiMoveSpeed = -3;
   else if (gInventory.Y > -30) GuiMoveSpeed = -2;
   else if (gInventory.Y > -40) GuiMoveSpeed = -1;
   gInventory.Y += GuiMoveSpeed;
   if (gInventory.Y == -40) MoveGuiUp = false;
 }
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Khris on Sat 23/01/2010 17:28:53
Instead of all the ifs, you could use GuiMoveSpeed = gInventory.Y / (-8) + 1;
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Calin Leafshade on Sat 23/01/2010 17:33:17
Thats true, although with the moving down animation i wanted to get a kind of 'ease in/out' feel. And i couldnt be bothered to come up with an equation for it just for the sake of 40 pixels and then i just copy/pasted for the moveup part.
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Dualnames on Sat 23/01/2010 18:57:34
Magma42, use the awesome Tween Module by Edmundo Ruiz!
You can tweak size,position, and all! And very easy, and also very good looking. I recommend it!

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=38015.0
Title: Re: Animating GUI Inventory Bar, is there another way?
Post by: Rex Mundane on Sat 23/01/2010 20:53:26
Oh now, that Tween looks particularly useful. Much thankings, Dual.