Animating GUI Inventory Bar, is there another way?

Started by Rex Mundane, Fri 22/01/2010 06:57:00

Previous topic - Next topic

Rex Mundane

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:
Code: ags
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?

Goldfish

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.

Khris

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.

Goldfish

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.
}

?


Rex Mundane

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.

Crimson Wizard

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!

Matti


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.

Calin Leafshade

#7
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

Code: ags


  
  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;
  } 

Khris

Instead of all the ifs, you could use GuiMoveSpeed = gInventory.Y / (-8) + 1;

Calin Leafshade

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.

Dualnames

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
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Rex Mundane

Oh now, that Tween looks particularly useful. Much thankings, Dual.

SMF spam blocked by CleanTalk