Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: DonB on Fri 13/01/2006 15:44:44

Title: Putting animating gif files in a view [SOLVED]
Post by: DonB on Fri 13/01/2006 15:44:44
I can't seem to put animating gif files in a view, or do i have to make every single frame in the view,

like, for example:

(http://home.unet.nl/carl/anders/seduce4.gif)

..

these are 6 frames, if i have to put them 1 by 1 in the view, thats no real problem, but then, where can i change the frametime??

still.. better for me would work if i could put an entire .gif animating file into a view
Title: Re: Putting animating gif files in a view
Post by: DoorKnobHandle on Fri 13/01/2006 16:03:32
Unfortunately you can't import a .gif file just like this with AGS.
Just import all of them (preferably by clicking right into the sprite-manager field and choosing "Quick import mutliple sprites...") and then just place them in a view. To change the framerate of the whole animation, you can use a parameter when you call the "animate" function with AGS script, to change the frame rate or duration of ONE frame, you can click on "delay" in the view-manager and change this frames delay.
Title: Re: Putting animating gif files in a view
Post by: strazer on Fri 13/01/2006 16:08:55
In newer AGS versions, you can right-click on an empty area in the Sprite manager, then choose "Quick import GIF/FLC frames..." from the context menu.

Edit:

Oh, directly putting them in a view? Nevermind.
Title: Re: Putting animating gif files in a view
Post by: DonB on Fri 13/01/2006 16:11:44
Thanks a lot for helping me on the track a bit.. i'm still not there tho..

If i import the frames into a view, and i do preview this loop, I can increase delay.. tho.. if i click this away.. its still the default 5 delay..
How do i increase this.. you mention an animate function script parameter, I don't know a damm about scripting.. so could you explain this very slowly..

Also.. if I got them all increased, I want ONE frame to stand out and have a longer delay.. how is this possible?

Also, I want this view only to be played once!

Where is this view manager you talk about?

Help appreciated..
Title: Re: Putting animating gif files in a view
Post by: DoorKnobHandle on Fri 13/01/2006 16:27:14
Strazer is right, but in the end it doesn't matter HOW you import the sprites. From what you wrote, it seems that you have them all imported correctly and put them in a view.

Don't worry about framerates for now.

Now somewhere in your script you need to "start" that animation (triggering it would be the better name). Let's say you want a GUI button to trigger that animation. So you'd click on "Script" and then on "interface_click". There you need to add something like this:


function interface_click ( int gui, int button )
{
   if ( gui == MYGUI )
   {
      if ( button == 0 )
      // if button 0 was pressed
      {
           // animate player character
           player.Animate(5, 3, eOnce, eBlock );
      }
   }
}


This would animate the player character using loop 5, a framerate of 3, one time and blocking. Remember to replace "MYGUI" with the name of the gui that your button is on and the "button == x" with the number of your button, the loop number (5) with the actual loop number of your animation and of course the speed of the animation (3) with the speed that you thing fits best.
Title: Re: Putting animating gif files in a view
Post by: Khris on Fri 13/01/2006 19:30:26
Quote from: DonB on Fri 13/01/2006 16:11:44If i import the frames into a view, and i do preview this loop, I can increase delay.. tho.. if i click this away.. its still the default 5 delay..
The preview function of the view editor is only for previewing, altering the speed here won't affect the in-game setting. It's mainly used to e.g. check if a walk-cycle looks good and to figure out an appealing speed for later in-game use.
Below each frame it says: "SPD: 0" Click on that, now enter any number you want.
When you animate the sprite later on, this number is added to the chosen animation speed, allowing you to display certain frames longer than others.

Btw, I'm pretty sure this is well explained in the helpfile ;)
Title: Re: Putting animating gif files in a view
Post by: DonB on Sat 14/01/2006 13:09:57
Thanks a lot dkh, Im one step further, but it says there's a bug with the given script when i trie to run it, of course this is a probably noob-ish fault of myself.. but could u guys tell me what I did wrong?

#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click ( int gui, int button )
{
   if ( gui == ICONBAR )
   {
      if ( button == 1 )
      // if button 1 was pressed
      {
           // animate player character
           player.Animate(6, 2, eOnce, eBlock );
      }
   }
}

it says; 'gui' is a global var; cannot use as name for local

and about that "player.Animate(6, 2, eOnce, eBlock );" line.. i dont understand.. so 6 is the loop and 2 is the speed.. but how does AGS know what view to be used then?

Appreciated!

Khrismuc thanks, that's very clear.. appreciated!
Title: Re: Putting animating gif files in a view
Post by: Ashen on Sat 14/01/2006 13:21:36
gui is an internally defined AGS thing (as in gui[5].Visible = true), so just use an other word. Tradition would say interface, as that's what interface_click has always used. (And still does -  it's been left in the global script by default, even though it's obsolete. dkh's script wasn't meant to be taken 'as is', it was just a guide.)
Or, don't use interface_click at all, use the individual control functions.

Quotehow does AGS know what view to be used then?
Read the manual:
Quote from: The Manual: Character.AnimateBefore using this command, you should use LockView in order to select the view you want to animate with and prevent any automatic animations (eg. walking or idle animations) from playing.

So, the current script would just use loop 6 of whatever view player was currently using (most likely their walking view) - which could cause a crash if there wasn't a loop 6 in that view. (Again, dkh's script was just a guide.)
Title: Re: Putting animating gif files in a view
Post by: DoorKnobHandle on Sat 14/01/2006 13:22:56
(1) Change the "gui" to "interface" (sorry, my mistake).


#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click ( int gui, int button )
{
   if ( gui == ICONBAR )
   {
      if ( button == 1 )
      // if button 1 was pressed
      {
           // animate player character
           player.Animate(6, 2, eOnce, eBlock );
      }
   }
}


That will fix the error.

(2) Your question:
AGS will use the view, that the character currently has for animating! If you want to be really safe, then add a line before the "player.Animate":


// be safe and set player view first
player.LockView ( 12 );
// animate player character
player.Animate(6, 2, eOnce, eBlock );
// now - after the animation finished playing - unlock the view again
player.UnlockView ();


But you don't NEED the LockView and UnlockView function calls if you have your animation stored in the view with all the walking sprites for your character. They are only needed if you have one view with the character walking and ANOTHER view with all his "special" animations - such as jumping/shooting/pickung sth. up...

Hope this helps!

Make sure to use the [*code] and [*/code] tags without the stars next time when you want to post code - this makes reading it much easier!

EDIT: Ashen's reply was faster, but maybe my reply can still help you!
Title: Re: Putting animating gif files in a view
Post by: DonB on Sat 14/01/2006 16:47:05
Tbh.. when I saw the error I already searched for what it could be.. and i saw the others scripts had interface in stead of gui, so i already tried changing that..

now i did change gui again in interface, then it says:

error: line85, variable 'interface-click' is already defined..

This line85 is not included by the previous code.. it's from an already-existing code in the script-interface

line 85:

85. function interface_click(int interface, int button) {
86. if (interface == ICONBAR) {
87.    if (button == 4) {  // show inventory
88.      show_inventory_window();
Title: Re: Putting animating gif files in a view
Post by: DoorKnobHandle on Sat 14/01/2006 16:52:32
Yeah, now you have 2 "interface_click" functions in your script. The one that I "gave" you and another old version that was there before, which was written by AGS for the functionality of the standard GUIs.

If you have don't have any default GUIs anymore (and changed them ALL into your new ones), then you can just delete the whole interface_click function starting in line 85 and going to the end (where the }-bracket closes the function).

If you still want to use the default AGS-GUIs and just added your GUI with the button on it, then simply combine the functions. That means that you need to erase the function, that I gave you and copy the content of this function into your older interface_click function in line 85:


function interface_click(int interface, int button) {

// PASTE THE CONTENT FROM OTHER FUNCTION HERE!
if ( interface == MYGUI )
// .........
// END OF PASTED CODE

if (interface == ICONBAR) {
if (button == 4) {  // show inventory
show_inventory_window();


This should be everything.
Title: Re: Putting animating gif files in a view
Post by: DonB on Sat 14/01/2006 19:20:31
Thanks a lot, appreciated!
Title: Re: Putting animating gif files in a view
Post by: DonB on Sat 14/01/2006 21:35:46
It doesnt say its bugged now.. but it aint working either..


function interface_click(int interface, int button) {

if ( interface == ICONBAR )
if ( button == 1 )
// if button 1 was pressed
// animate player character
Ã,  player.Animate(3, 3, eOnce, eBlock );

if (interface == ICONBAR) {
if (button == 4) {Ã,  // show inventory
Ã,  Ã,  Ã,  show_inventory_window();


Help appreciated.. this scripting is driving me mad..
Can't it be that the button of the default AGS gui ICONBAR GUI isnt called 1,2,3,4 and so on?
Title: Re: Putting animating gif files in a view
Post by: DoorKnobHandle on Sat 14/01/2006 21:47:23
I'm not sure, but adding brackets _may_ help:


function interface_click ( int interface, int button )
{
   if ( interface == ICONBAR )
   {
      if ( button == 1 )
      // if button 1 was pressed
      {
         // animate player character
         player.Animate ( 3, 3, eOnce, eBlock );
      }
      if ( button == 4 )
      { 
         // show inventory
         show_inventory_window ( );
      }
      // ...
}
Title: Re: Putting animating gif files in a view
Post by: DonB on Sat 14/01/2006 21:55:18

#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button)
{
if ( interface == ICONBAR )
{
if ( button == 1 )
// if button 1 was pressed
{
// animate player character
player.Animate(3, 3, eOnce, eBlock );
}
    if (button == 4)
{
// show inventory
show_inventory_window();
    }
    else if (button == 5) {   // use selected inventory
      if (character[ GetPlayerCharacter() ].activeinv >= 0)
        SetCursorMode(4);


Hmzz.. i did what u said.. still not working, but.. like i said.. cant it happen to be caused by the default GUI ICONBAR? , are these also, button0 or 1 or 2 and so on, there..
Title: Re: Putting animating gif files in a view
Post by: DoorKnobHandle on Sat 14/01/2006 21:57:08
That _should_ work as long as your button is on the gui, that is named ICONBAR and as long as it is the button number 1 (left-click and select the button and look at the title of the properties window where it says "control : x" that is coming up).
Title: Re: Putting animating gif files in a view
Post by: DonB on Sat 14/01/2006 21:59:06
I figured that.. well.. then I'm down.. really cant see the bug..
Title: Re: Putting animating gif files in a view
Post by: Ashen on Sat 14/01/2006 23:16:17
Another obvious thing to check: Have you set button 1 to 'Run script'? By default, I think those buttons (ICONBAR, objects 0-3) are set to 'Set cursor mode'.

Alternatively, as I've said before, don't use interface_click at all, use the individual control functions.
Title: Re: Putting animating gif files in a view
Post by: DonB on Mon 16/01/2006 14:23:47
Thank you guys, the "Set Cursor Mode becomes Run Script" did the thing..

once again.. Solved