Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: SinSin on Wed 10/02/2010 22:08:59

Title: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Wed 10/02/2010 22:08:59
AGS version 3.1.0

I've been trying this for ages but I cannot do it
Basically I want my GUI to pop up when my mouse cursor is at the bottom of the screen, I tried a method that BEN wrote down ages ago but obviously AGS has come along way since then and now this method wont work
here is what I have
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute()
 {
if((mouse.y > 194) && (gui_ypos > 0)){
 gTask.SetPosition(gTask , 0 , gui_ypos - 200); //where GUI# is the name or number of the GUI you're moving
 gui_ypos ++;
 }


also I have this in my Glabal script.ash

 int gui_ypos = 1;

Debugger claims Type Mismatch: cannot convert GUI* to 'Int'            ???
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: Matti on Wed 10/02/2010 22:31:55
It seems you want the GUI to scroll up from the bottom, not to pop up? In any case, this has been a question a few weeks ago:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=39938.0

The conclusion was: The Tween module is your friend:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=38015.0
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: Dualnames on Wed 10/02/2010 22:35:29
Quote from: Sinsin on Wed 10/02/2010 22:08:59
AGS version 3.1.0

I've been trying this for ages but I cannot do it
Basically I want my GUI to pop up when my mouse cursor is at the bottom of the screen, I tried a method that BEN wrote down ages ago but obviously AGS has come along way since then and now this method wont work
here is what I have
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute()
 {
if((mouse.y > 194) && (gui_ypos > 0)){
 gTask.SetPosition(gTask , 0 , gui_ypos - 200); //where GUI# is the name or number of the GUI you're moving
 gui_ypos ++;
 }


also I have this in my Glabal script.ash

 int gui_ypos = 1;

Debugger claims Type Mismatch: cannot convert GUI* to 'Int'            ???

Quote from: 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

I'm not like selling anything, but it's a darn easy, darn impressive module to handle trans, position, scale, size.
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Wed 10/02/2010 22:42:19
cheers guys  you have been most helpful  ;D
Title: Tween module HELP! Getting a GUI tween to stop repeating and be enabled
Post by: SinSin on Thu 11/02/2010 02:30:36
Quote from: Sinsin on Wed 10/02/2010 22:42:19
cheers guys  you have been most helpful  ;D
Actually Ive just seen this mod and downloaded it   but I'll be damned if I know how to use it, It just is'nt clear on where I should write anything.


Can anyone help ?

Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: monkey0506 on Thu 11/02/2010 06:22:52
The function you're looking for is GUI.TweenPosition. I don't know the full parameter list off-hand, but it should show up in the calltip when you put the function in. Something like:

gIconbar.SetPosition(0, System.ViewportHeight);
gIconbar.TweenPosition(0, System.ViewportHeight - gIconbar.Height, eEaseIn);


Like I said, I don't know the full parameter list so that code won't work as-is, but that's the basic gist of it. You would call that from repeatedly_execute depending on the mouse position. You would use the same TweenPosition function to slide it back out.

Although really for one single GUI it's not that hard to just do:

function repeatedly_execute() {
  int ypos = (System.ViewportHeight - gIconbar.Height);
  if (mouse.y >= ypos) {
    if (gIconbar.Y > ypos) gIconbar.Y--;
  }
  else if (gIconbar.Y < System.ViewportHeight) gIconbar.Y++;
}
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Thu 11/02/2010 13:18:25
So Iv set the GUI

gTask

What I can gather is that Iv also set its tween to point ???
This wont work either
says

GlobalScript.asc(14): Error (line 14): Type mismatch: cannot convert 'int' to 'float'  ???  

Im really sorry ifI'm coming across as stupid but this module is proper doin ma head in . :(


function repeatedly_execute()
{
gTask.SetPosition(0, System.ViewportHeight);
gTask.TweenPosition(1.0, System.ViewportHeight - gTask.Height, eEaseInTween);   //This is line 14

int ypos = (System.ViewportHeight - gTask.Height);
 if (mouse.y >= ypos) {
   if (gTask.Y > ypos) gTask.Y--;
   
    }
 else if (gTask.Y < System.ViewportHeight) gTask.Y++;
}
 
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: hedgefield on Thu 11/02/2010 15:11:47
A float always has a decimal point in it, so you need to put 125.0 in the TweenPosition function instead of just 125.

Actually I'd recommend starting with a value like 1.0.
125.0 is reeeaaaallllyyyy really slow.
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Thu 11/02/2010 15:42:15
Sigh I made the ammendment and I'm still nowhere near   


#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute()
{
gTask.SetPosition(0, System.ViewportHeight);                            \\ <----- THIS IS THE CULPRIT
gTask.TweenPosition(1.0, System.ViewportHeight - gTask.Height, eEaseInTween);

int ypos = (System.ViewportHeight - gTask.Height);
  if (mouse.y >= ypos) {
    if (gTask.Y > ypos) gTask.Y--;
   
     }
  else if (gTask.Y < System.ViewportHeight) gTask.Y++;
}
   

#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


ERROR  GUI.Y Co-ordinates specified are out of range
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: Khris on Thu 11/02/2010 15:54:45
Try
  gTask.SetPosition(0, System.ViewportHeight - 1);
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Thu 11/02/2010 16:02:28
EDIT:  Thanks for all the help so far
So I've been doing some tinkering and this is the closest I've got
Currently this code lets the game load up and the GUI in question (gTask) appears but is blurred out and blinking, Also it follows my mouse upward Hahhah
Im so close    any ideas ?


function repeatedly_execute()
{
 gTask.SetPosition(0, 153);
 gTask.TweenPosition(1.0, 0, 0, eEaseInTween, eBlockTween);
 
 int ypos = (System.ViewportHeight - gTask.Height);
 if (mouse.y >= ypos) {
   if (gTask.Y > ypos) gTask.Y--;
    }
 else if (gTask.Y < System.ViewportHeight) gTask.Y++;  
}  
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: monkey0506 on Thu 11/02/2010 21:29:49
I never meant for you to script it yourself and use the Tween module. Use one or the other. Not both.

So, use:

 gTask.SetPosition(0, 153);
 gTask.TweenPosition(1.0, 0, 0, eEaseInTween, eBlockTween);


OR:

 int ypos = (System.ViewportHeight - gTask.Height);
 if (mouse.y >= ypos) {
   if (gTask.Y > ypos) gTask.Y--;
 }
 else if (gTask.Y < (System.ViewportHeight - 1)) gTask.Y++;


Though I don't know why it would be telling you max tweens exceeded (if you went for the Tween route).

And this code wasn't strictly intended for use as-is (as I said). You'll need to customize it to fit your own needs.
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: tzachs on Thu 11/02/2010 21:58:02
With the TweenPosition line you made the gui will go to (0,0) on every repeatedly execute (and then go down because of the other code), and that would explain gui "blinking".

You can do something like this:

function repeatedly_execute()
{
   int ypos = (System.ViewportHeight - gIconbar.Height);
   if (mouse.y >= ypos) {
         //GUI scrolls up
         gIconbar.TweenPosition(1.0, gIconbar.x, ypos, eEaseInTween, eBlockTween);
   }
   else if (gIconbar.Y < System.ViewportHeight - 1) {
        //GUI scrolls down
        gIconbar.TweenPosition(1.0, gIconbar.x, System.ViewportHeight - 1, eEaseInTween,  eBlockTween);
   }
}
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Thu 11/02/2010 22:39:50
edited the phrase Iconbar.x to suit script
All i need now is to be able to use it (currently its constantly greyed out)

Should it be paused when scrolled up?

Sorry but I'm hopeless with code
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: tzachs on Fri 12/02/2010 16:49:49
Yes, my bad, change this line:

if (mouse.y >= ypos) {


to this:

if (mouse.y >= ypos && gIconBar.Y != ypos) {


That should do it...
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Fri 12/02/2010 17:03:45
Quote from: tzachs on Fri 12/02/2010 16:49:49
Yes, my bad, change this line:

if (mouse.y >= ypos) {


to this:

if (mouse.y >= ypos && gIconBar.Y != ypos) {


That should do it...


This just makes the bar go in then out again and again
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: monkey0506 on Fri 12/02/2010 19:34:46
That's the reason I had them in a nested condition so you don't have to recheck the same condition needlessly:

if (mouse.y >= ypos) {
 if (gTask.Y != ypos) gTask.TweenPosition(1.0, gTask.X, ypos, eEaseInTween, eBlockTween);
}
else if (gTask.Y < (System.ViewportHeight - 1)) gTask.TweenPosition(1.0, gTask.X, System.ViewportHeight - 1, eEaseInTween,  eBlockTween);
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Fri 12/02/2010 19:45:48
I dont get it   What should I be doin now  Im confused.. Is tzachs right or not  ???
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: monkey0506 on Fri 12/02/2010 19:49:49
tzachs was correct (as I had already said previously) that you will want to check both conditions. Again, as I already said, my original code snippets weren't intended for use as-is. However, seeing as you have made it apparent that you are not very well oriented with scripting, the code snippet I posted above should be suited to your task.

tzachs was incorrect however as to the logical grouping. The logic of the outer if statement and the else clause should only consider the mouse's y co-ordinate. The inner if statement is required to check the GUI's y co-ordinate as well.

So tzachs was both correct and incorrect.
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: tzachs on Fri 12/02/2010 22:25:43
Yes, I was half correct, monkey is completely correct...
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: monkey0506 on Fri 12/02/2010 23:59:05
An alternative to the grouping I showed above would be simply to change the else clause to re-evaluate the mouse's y co-ordinate in addition to evaluating the GUI's y co-ordinate. The reason that I would say this is wrong is because it's a less efficient way of programming than simply splitting the if statement as I did.

Hope there's no offense taken tzachs. I'm just a bit of a Nazi when it comes to scripting I guess. Of course I was born in Germany... ::)

Although actually I try to be lenient when it comes to things like programming style, matters like consistency and efficiency tend to grind my gears a bit. Like the fact that there's loads more overhead in using the Tween module for a simple GUI movement than just moving the GUI yourself...but I understand that it vastly simplifies things for those who aren't as skillful with scripting as myself, so it's a trade-off there. :P
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: tzachs on Sat 13/02/2010 00:49:14
No offense taken :) , I actually used the same code myself for my GUI, I just posted from memory and didn't check myself...  

I actually prefer using the Tween Module though, because it makes experimenting easier regarding the timings, so actually I think it's less overhead then coding it yourself (if you are an experimenter)...
I also find that using a module is better in most cases because even something that looks simple can have caveats that you didn't think of and were probably handled in the module. This can save you precious time, which is more critical for me than efficiency for adventure games (obviously not the approach I would take for writing drivers or some real-time critical code)...
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: monkey0506 on Sat 13/02/2010 05:36:07
On my computer AGS games are real-time critical. :=

D3D Driver? Forget about it! Pixel shader 2.0? Forget about it! FPS over 30 at a resolution over 640x400? Forget about it! ::)
Title: Re: Tween module HELP! Getting a GUI tween to stop repeating and be enabled
Post by: SinSin on Sat 13/02/2010 10:43:07
Quote from: monkey_05_06 on Fri 12/02/2010 19:34:46
if (mouse.y >= ypos) {
 if (gTask.Y != ypos) gTask.TweenPosition(1.0, gTask.X, ypos, eEaseInTween, eBlockTween);
}
else if (gTask.Y < (System.ViewportHeight - 1)) gTask.TweenPosition(1.0, gTask.X, System.ViewportHeight - 1, eEaseInTween,  eBlockTween);


So am i using this example or the tween module one...  I'm confused

I have the tween module imported already and now i have this as my code  .. what should i change  and indeed where  ???
(Regarding the gui going up and down continuosly??)


#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute()
{
   int ypos = (System.ViewportHeight - gTask.Height);
   if (mouse.y >= ypos && gTask.Y != ypos) {
         //GUI scrolls up
         gTask.TweenPosition(1.0, gTask.X, ypos, eEaseInTween, eBlockTween);
   }
   else if (gTask.Y < System.ViewportHeight - 1) {
        //GUI scrolls down
        gTask.TweenPosition(1.0, gTask.X, System.ViewportHeight - 1, eEaseInTween,  eBlockTween);
   }
}

#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: tzachs on Sat 13/02/2010 18:45:29

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute()
{
   int ypos = (System.ViewportHeight - gTask.Height);
   if (mouse.y >= ypos) {
      if (gTask.Y != ypos) {      
         //GUI scrolls up
         gTask.TweenPosition(1.0, gTask.X, ypos, eEaseInTween, eBlockTween);
      }
   }
   else if (gTask.Y < System.ViewportHeight - 1) {
        //GUI scrolls down
        gTask.TweenPosition(1.0, gTask.X, System.ViewportHeight - 1, eEaseInTween,  eBlockTween);
   }
}

#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Sat 13/02/2010 18:52:20
Good stuff fella  ;D
but one thing remains, when a button is pressed on the Gui, The Gui dissapears completely then when the mouse moves above the ypos the Gui then returns and lowers, Also the character wont go anywhere or interact/look 
Title: Re: Unpausing ??? HELP!
Post by: SinSin on Mon 15/02/2010 00:13:50
Ok So Iv stopped being a COMPLETE NOOB and realised that what I was doing was if fact Pop up modal (which automatically pauses the game) So I changed its settings to Normal initially on, Now the GUI works fine it is great I thank you for all your help this far  :)

The only problem I have now is that after the GUI has tweened off my character will not move, look_at or anything at all and a Gui Label which is on another GUI wont show the names of hotspots even tho its text is @OVERHOTSPOT@   .   There are walkable areas there and yes he is stood well within the area too,
I think that the tween is pausing the game somehow   Any Ideas on a fix.

Any help will be much appreciated
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: Dualnames on Mon 15/02/2010 00:26:38
Tween isn't pausing the game. Is the cursor in wait cursor when you can't move or walk ecc?

To make sure have something like this on a repeatedly_execute..


if (IsGamePaused()==1) UnPauseGame();


But something else is the issue. Something to do with the GUI, I think there's a BIG clickable GUI all over the screen causing all this. And you probably have made something wrong, without noticing it. But that would only be the problem if it was totally transparent.
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Mon 15/02/2010 00:39:53
Quote from: Dualnames on Mon 15/02/2010 00:26:38
Tween isn't pausing the game. Is the cursor in wait cursor when you can't move or walk ecc?
Yeah the wait cursor is active when the GUI is not visible, However when the GUI pops up the Wait cursor changes to the active cursor

Quote
To make sure have something like this on a repeatedly_execute..


if (IsGamePaused()==1) UnPauseGame();


But something else is the issue. Something to do with the GUI, I think there's a BIG clickable GUI all over the screen causing all this. And you probably have made something wrong, without noticing it. But that would only be the problem if it was totally transparent.

There is only one other GUI and its always visible its only a bar at the top of the screen with a label inside it
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: Dualnames on Mon 15/02/2010 02:31:02
Quote from: Sinsin on Mon 15/02/2010 00:39:53
Quote from: Dualnames on Mon 15/02/2010 00:26:38
Tween isn't pausing the game. Is the cursor in wait cursor when you can't move or walk ecc?
Yeah the wait cursor is active when the GUI is not visible, However when the GUI pops up the Wait cursor changes to the active cursor

Quote
To make sure have something like this on a repeatedly_execute..


if (IsGamePaused()==1) UnPauseGame();


But something else is the issue. Something to do with the GUI, I think there's a BIG clickable GUI all over the screen causing all this. And you probably have made something wrong, without noticing it. But that would only be the problem if it was totally transparent.

There is only one other GUI and its always visible its only a bar at the top of the screen with a label inside it

Your tweening is neverending from what I understand. The tween command doesn't stop. put a return after each tween command for me.
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Mon 15/02/2010 09:05:23
Quote

Your tweening is neverending from what I understand. The tween command doesn't stop. put a return after each tween command for me.

Just for the record define return please,
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: tzachs on Mon 15/02/2010 12:03:34
Hmmm, I used the exact same code and had no problems.
I don't see how adding a "return" statement after the tween will help, maybe you have something else going on there (maybe there's an invisible clickable gui blocking the screen or something of that sort)?
If you want to post a sample with the problem, I can try and solve it...
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Mon 15/02/2010 16:23:57
Quote from: tzachs on Mon 15/02/2010 12:03:34
Hmmm, I used the exact same code and had no problems.
I don't see how adding a "return" statement after the tween will help, maybe you have something else going on there (maybe there's an invisible clickable gui blocking the screen or something of that sort)?
If you want to post a sample with the problem, I can try and solve it...

Just at work at the mo but when I get home I will do, Do you just wanna see the repeatedly execute section or do you need more?   Again thanks
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: tzachs on Mon 15/02/2010 16:38:43
I honestly don't know, it depends where the problem is...
The ideal thing is for you to make a sample that illustrates the problem, and then upload the project (it doesn't have to be your game if that bothers you, just a sample) so I can download it, open with ags and debug to see the problem.
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Mon 15/02/2010 20:33:54
        This  (http://www.mediafire.com/file/zmmjgjxoyoy/GUI%20Monkey.rar)       is the whole file I have been working with   
                       Please note it the wait cursor is slightly darker than the usual cursor


Thanks
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: tzachs on Mon 15/02/2010 20:41:47
Ahh, you didn't copy my code correctly before...
Change

else if (gTask.Y < System.ViewportHeight) {

to

else if (gTask.Y < System.ViewportHeight - 1) {
Title: Re: Animating a GUI to Pop up from the bottom of the screen HELP!
Post by: SinSin on Mon 15/02/2010 21:05:58
Quote from: tzachs on Mon 15/02/2010 20:41:47
Ahh, you didn't copy my code correctly before...
Change

else if (gTask.Y < System.ViewportHeight) {

to

else if (gTask.Y < System.ViewportHeight - 1) {


Yay fixed it thanks dude   I did have the code copied exactly at one point as I recall but I must have changed it   
when i was tinkering lol 

Thanks for all your hard work     now go have a beer     and i will now shut up ...For now ...