animate gui button

Started by Timosity, Thu 19/06/2003 16:47:54

Previous topic - Next topic

Timosity

I'm pretty sure this is not possible but it would be handy in my game.

eg. In a gui for quitting  having a button for a graphic that animates, like in some sierra games. (not mouse over, or pressed) For a picture not a pressable button

Also for sierra style speech with bg, I know you can have an animated talking view, but to have an animated talking view within the text box, not outside it.

Also I tried just having a still picture in the speech text box but it doesn't show up, it works for a regular gui, but not a text window gui. It would be silly to have a separate gui for every section of speech.


Is any of this possible? I can't remember seeing it in any ags game

Scummbuddy

Perhaps go to a new room, kinda of like in CMI, and there have an animated object go continuous, and then draw a hotspot over it?
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Timosity

I don't know how it would help having a hotspot over it, or the reason you mean, assuming the 1st question, but I guess you could have a new room, with the background looking like the gui, and an object animating for the pic, but I think I'll just keep a still pic for the quitting gui.

as for the talking ones, it couldn't be too hard to implement an animated gui button, or have the talking animation located inside the text window.

I guess it has something to do with the resizing of text windows for the amount of text. but you could have the image aligned to the left or right, top or bottom, or combo ie left top.

I don't know, I guess I can only suggest and see if anyone else thinks it's a good idea

Scummbuddy

well i meant to 'if  click on hotspot' which is over the animating one... then exit game, or whatever you'd like.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Timosity

thanks for replying Scummbuddy, but I musn't have been too clear, but I don't need to click on the animated image I could have normal buttons for quit or cancel.

Also I'm pretty sure if you put a hotspot over an object, the object goes over the hotspot anyway

Scummbuddy

#5
oh, i reread what you posted.  how about in repeatedly execute

SetGUIBackgroundPic

or

SetButtonPic

and keep them going?

But, yes, if it was an option to have animated buttons, it would be a lot neater for code and to look at.  Edit* I thought this was to be added to the tracker quite awhile ago... but I don't see it.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Timosity

Thanks Scummy,

SetButtonPic might work, I'll give it a go but once a gui comes up, the game is paused I guess, so it might not work, but trying is the only way to know.

Ahh, It's 3am, nearly bed time

Timosity

#7
OK, I've gotten close with using the SetButtonPic in the repeatedly execute, but it only seems to work with the wait command which defeats the purpose.

this is the simple script that works in the repeatedly execute with the wait
after setting the globalint. it resets the globalint to 0 when you click the gui off, except you can't cause the wait pauses the game.

if (GetGlobalInt(60)==1){

SetButtonPic(16,2,1,959);
Wait(40);

SetButtonPic(16,2,1,960);
Wait(40);
}



I tried to set a timer when the gui came on and use this script

if (GetGlobalInt(60)==1){
if (IsTimerExpired(10)==1){
SetButtonPic(16,2,1,959);
SetGlobalInt(60,2);
}
}

if (GetGlobalInt(60)==2){
if (IsTimerExpired(20)==1){
SetButtonPic(16,2,1,960);
SetGlobalInt(60,1);
}
}

I set the timers here:

function interface_click(int interface, int button) {

if (interface == 16){

SetTimer(10,40);
SetTimer(20,80);

 if (button == 1){

    GUIOff(16);
     GUIOn(1);
     SetGlobalInt(60,0);
     Wait(1);
     
     Display("...Or don't, it's up to you!");

character[EGO].x = 240;
character[EGO].y = 149;
ReleaseCharacterView(EGO);
SetCharacterSpeed(EGO,5);

StopMusic();
SetMusicRepeat(1);
PlayMusic(8);

}
}

I set 2 timers apart so they were a second apart, I guess you have to set timers outside the repeatedly execute so it doesn't continually set them,

but then the animation will only happen once, but it doesn't happen at all, in this code, the first time the gui comes up it displays one frame, the next time and every time after that, the second frame comes up.

Can anyone think of a way the timer could work or another command that doesn't pause the game to allow this to happen.

It's for a fake death scene, so the death "game over" interface comes on and after you click it off it returns to where you were up to.


EDIT:

I also tried this

function repeatedly_execute() {
 // put anything you want to happen every game cycle here

if (GetGlobalInt(60)==1){
if (IsTimerExpired(10)==1){
SetButtonPic(16,2,1,960);
SetGlobalInt(60,2);
SetTimer(20,40);
}
}

if (GetGlobalInt(60)==2){
if (IsTimerExpired(20)==1){
SetButtonPic(16,2,1,959);
SetGlobalInt(60,1);
SetTimer(10,40);
}
}


}



after setting the timer here

if (interface == 16){
SetTimer(10,40);
etc

and it still didn't work, what am I doing wrong, and is there a possible solution or should I give up on the idea?

Dorcan

I made a script that may help you animating a GUI Button. It works fine for me
I suggest you to download the source code.

Here is the tutorial link :
http://host.deluxnetwork.com/~dorcan/script.php?id=7&langue=en

Timosity

Thanks Dorcan, I'll give it a go and tell you if I get it to work.

Thanks again.

Dorcan

A little mistake  ::) (corrected on my website):

function StartGUIAnimation ( int GUI, int Button, int Which, int GUIView )  {
int I=0;
int K=-1;
     while  ( I < MaxAnim )   {
          if  (  ( guianim [ I ] .gui == GUI ) && ( guianim [ I ] .button==Button ) && ( guianim [ I ] .which==Which )  )   {
           K=I;        //instead of K=GUI
           ...

Tell me if you find a bug

Timosity

#11
Thanks Dorcan, I haven't got time to try it at the moment, so probably around 24 hours from now.

Edit: I just had a quick try before I go out,

The only thing I'm not sure about is this bit

function SetGUIView ( int ID, int Start, int End, int Speed, int Repeat, int Sound )  {

Cause I have to define these views, I'm not sure what these (int ID, int Start, int End,) are actually referring to, maybe you could make it more clear or give an example in the tutorial, also the ints for the other functions, just to make it clearer to anyone reading it.

Thanks

Dorcan

#12
Well there is 2 pages in my tutorial, and the second one explain the functions.
You must have missed the button I think... Oh I know! I haven't translated "Page suivante" which means "Next page". I'll change the look, it's not very clear. :P

http://host.deluxnetwork.com/~dorcan/script.php?id=7&page=2

Edit : Ok, I have made it, now it should be obvious that there are several pages.

Timosity

Yeah, I did miss that second page which does come in handy.

I haven't got it to work properly yet though, It could be where I'm putting my code, I'm not sure.

Cause it only works the second time the gui is loaded, then every other time, but that is only if I leave out the "StopGUIAnimation"



This is where I put the StartGUIAnimation

if (interface == 16){
StartGUIAnimation(16, 2, 1, 89);
 if (button == 1){
         
     GUIOff(16);
     GUIOn(1);
     Wait(1);
     Display("...Or don't, it's up to you!");


character[EGO].x = 240;
character[EGO].y = 149;
ReleaseCharacterView(EGO);
SetCharacterSpeed(EGO,5);

StopMusic();
SetMusicRepeat(1);
PlayMusic(8);
}
}


I'll keep trying playing around with it to see if I can figure it out,

also, I've tried to get rid of the sound that you incorporated into the script but It causes an error if I remove it, even if I take out this line:

PlaySoundEx ( guiview [TView] .sound, 3 ) ;

(not in compiling but it won't run the game)


It's very impressive scripting there Dorcan, I can't believe how much scripting is needed for something seeming simple, I should have posted in the Tech forum initially and not the beginners.

Dorcan

That's a part of a code inside the interface_click function, right ?
Remember that interface_click is called only when an interface or a button is clicked.

So if you want the animation to start at the moment the GUI is loaded, you must put the StartGUIAnimation just before the command GUIOn

StartGUIAnimation(16, 2, 1, 89);
GUIOn(16);


BTW, about the sound, I made a very little mistake (again):

if ((guianim.frame==0)&&(guiview[TView].sound!=-1))

And if you don't want a sound to be played, sound value must be -1 in SetGUIView().

Timosity

I got it to work putting

StartGUIAnimation(16,2,1, 89);

in function game_start() {

and not having a StopGUIAnimation but then I decided to start from scratch again and now I can't get it to work at all, and I don't know what I've done wrong.


I don't know if it's the position in the script, all the code including the functions are before the function game_start() {
or else it doesn't recognise InitGUI(); cause it hasn't been defined unless I define the function before function game_start() {


with this line:
SetGUIView(89,977,979,5,1,-1);

*which I assume the view id means view 89 in the views tab in the editor
*start sprite in the animation in view 89 is 977
*end sprite in the animation in view 89 is 979 (it's a 3 frame animation)
*the speed is 5
*it repeats so it is set at 1
*no sound so it is -1

with it set like that I get an error when running the game, it shuts down and tells me the problem is on this line:

guiview [ID] .start   =Start;

if I change the view ID to a lower number it passes that error and then instead I get an error on this line: (note, I know it's the wrong view but I wanted to see if the number had anything to do with the error, and it must have)

if  (  ( guianim .frame==0 ) && ( guiview [TView] .sound!=-1 )  )
which is the one you said initially was a problem, the same error occurred with the old line of code.


It originally worked when I put this line in function game_start() {

StartGUIAnimation(16,2,1, 89);

*Where the gui is number 16
*button 2 is the button to animate
*using the normal picture 1
*on view 89

If I remove the 2 lines
SetGUIView(89,977,979,5,1,-1);
StartGUIAnimation(16,2,1, 89);

the game runs but obviously it won't do anything cause these are the important links to the ags editor.

I'm not sure what's going wrong, but you also said to put the line

StartGUIAnimation(16,2,1, 89);

before GUIOn(16);

but seeing as that is in a room script StartGUIAnimation isn't defined there so it won't work.

I had it working and now I'm just totally confused in why it now doesn't work.

any ideas, I hope you can understand what I've written.

Dorcan

#16
Ok, I see. Next time, could you post also the error messages ?

Let me explain some important things  ;):

1.  function SetGUIView ( int ID, int Start, int End, int Speed, int Repeat, int Sound )

int ID is the GUI View ID, but it is NOT the view in the AGS Editor.


2. At the begining of the script, as you can see in my tutorial, I have defined some variables :

Quoteint MaxAnim=20;

GUIVIEW    guiview [20] ;
GUIANIM   guianim [20] ; //Same as MaxAnim

You can see that GUIVIEW is an array with a size of 20.
SO, you can only have 20 views. Of course, you can modifiy this if you need more views.


3. With all that in mind, you can know understand why
SetGUIView(89,977,979,5,1,-1); can't work.
You have defined a VIEW ID as 89, but there is only 20 views max !

The correct line would be :
SetGUIView(0 to 20,977,979,5,1,-1);
...
...
StartGUIAnimation(16,2,1, 0 to 20);



4. Now the position in the script.
Everything must be at the begining of your global script, before game_start() and repeatedly_execute().


5. You said you needed the GUI Animation for a Death dialog.
I would suggest you creating a function called "DeathDialog()" in the global script :

Quotefunction DeathDialog(int death_view){
   StartGUIAnimation(16,2,1, death_view);
   GUIOn(16);
}

Then go in the Header Script, and paste this code :

Quoteimport function DeathDialog(int death_view);

Ok. Now, when the character die, just call, in any room script, the function DeathDialog with the appropriate death view.

BTW, I don't think the animation repeat must be set on 1, because the death animation would repeat again and again, and that wasn't the case in the sierra games I think...



If there is still problems with sound, just cut thoses lines :
Quoteif ((guianim.frame==0)||(guiview[TView].sound!=-1))
       PlaySoundEx(guiview[TView].sound, 3);

As I made this tutorial somewhat "quick", the functions weren't well explained enough. I'll see what I can do.

Hope it helps  ;D

Timosity

#17
Thanks again Dorcan, You're a Legend, I understand the code much better now, I haven't tried it yet but, I can see where I went wrong,  and thanks for the extra tips aswell.

Just to explain what I'm doing, after the player dies eg. for a drowning, it 1st goes through the normal character animations and then the gui comes up after with the gui button animation of 3 frames repeatedly (until the player clicks on another button on the gui to close it) of the character with bubbles coming out of his mouth.

There will also be different ones for different methods of dying, but, they are only fake deaths, cause I don't like games where you die, but to have death scenes is a bit of fun, and can scare the player into thinking they should have saved.

I've learned alot from this, and can see how much more technical you can get with ags. Thanks Again.

I'll tell you if I get it working

EDIT: Yep, It works fine, thanks 10 more times

SMF spam blocked by CleanTalk